{"id":6185,"date":"2017-03-17T13:25:30","date_gmt":"2017-03-17T16:25:30","guid":{"rendered":"http:\/\/blog.plataformatec.com.br\/?p=6185"},"modified":"2017-04-14T15:11:22","modified_gmt":"2017-04-14T18:11:22","slug":"small-data-with-elixir","status":"publish","type":"post","link":"https:\/\/blog.plataformatec.com.br\/2017\/03\/small-data-with-elixir\/","title":{"rendered":"Small data with Elixir"},"content":{"rendered":"

This is the first article in a series of articles about “small data” (in contrast to “big data”) in Elixir. We will start by defining what is “small data”, why it matters and then briefly describe the Flow<\/code> tool and what to expect in the next articles of the series.<\/p>\n

How small is small?<\/h2>\n

We define small data as data that can be processed by a single machine in a desirable time interval. Such work may be done in batches, where all the data is known upfront, or on streaming data, where one or more machines can keep up with the incoming rate of events without a need for synchronization.<\/p>\n

Yanpei Chen, Sara Alspaugh, and Randy Katz, from University of California, have characterized different MapReduce workloads<\/a>, and concluded that:<\/p>\n

\nFor job-level scheduling and execution planning all workloads contain a range of job types, with the most common being small jobs. These jobs are small in all dimensions compared with other jobs in the same workload. They involve 10s of KB to GB of data, exhibit a range of data patterns between the map and reduce stages, and have durations of 10s of seconds to a few minutes.\n<\/p><\/blockquote>\n

Ionel Gog, Malte Schwarzkopf, Natacha Crooks, Matthew P. Grosvenor, Allen Clement, and Steven Hand, from University of Cambridge and Max Planck Institute for Software Systems, when developing Musketeer<\/a> compared different solutions and found that<\/p>\n

\nFor small inputs (\u2264 0.5GB), the Metis single-machine MapReduce system performs best. This matters, as small inputs are common in practice: 40\u201380% of Cloudera customers\u2019 MapReduce jobs and 70% of jobs in a Facebook trace have \u2264 1GB of input.\n<\/p><\/blockquote>\n

Often the computation was not the bottleneck but reading the data from external sources. Being able to stream from and to external sources in parallel is paramount for the performance of such systems.<\/p>\n

Finally, Frank McSherry, Michael Isardm, and Derek G. Murray published “Scalability! But at what COST?”<\/a>. The COST of a given platform for a given problem is the hardware configuration required before the platform outperforms a competent single-threaded implementation<\/strong>.<\/p>\n

\nThe cluster computing environment is different from the environment of a laptop. The former often values high capacity and throughput over latency, with slower cores, storage, and memory. The laptop now embodies the personal computer, with lower capacity but faster cores, storage, and memory. While scalable systems are often a good match to cluster resources, it is important to consider alternative hardware for peak performance.\n<\/p><\/blockquote>\n

In other words, there is a large set of problems that are more efficiently solved on a single machine, as it avoids the costs in complexity, network communication and data checkpointing common to big data systems.<\/p>\n

What exactly constitutes small data depends on the problem, the data size (or its incoming rate) and the expected processing times. In this series of articles, we will explore solutions to different problems with the Flow<\/code> library<\/a>. Flow leverages concurrency on single-machines and may be a suitable option for small workloads, saving teams the need to resort to fully fledged big data solutions.<\/p>\n

GenStage and Flow<\/h2>\n

Last year we have introduced GenStage<\/a>, an abstraction for exchanging data between Elixir processes. GenStage was designed with back-pressure in mind so Elixir developers are able to consume data from external systems, such as Apache Kafka, RabbitMQ, databases, files and so on without overloading the system processing the data.<\/p>\n

Stages may be producers and\/or consumers of data. A single producer stage may have multiple consumers, which will receive events according to a chosen strategy. This means developers can create arbitrarily stage pipelines as a way to leverage concurrency.<\/p>\n

However, if developers are the ones responsible for building those pipelines, they may end-up with suboptimal workflows. That’s why we developed a tool called Flow<\/code>, built on top of GenStage<\/code>. Flow allows developers to express their data computations using functional operations, such as map<\/code>, reduce<\/code>, filter<\/code>, and friends. Flow also provides conveniences for data partioning and windowing. Once such parameters are specified, Flow<\/code> takes care of building a network of connected stages where the data flows through. Here is the classic (and clich\u00e9) example of using Flow for counting words on a file:<\/p>\n

File.stream!(\"path\/to\/file\")\n|> Flow.from_enumerable()\n|> Flow.flat_map(&String.split\/1)\n|> Flow.partition()\n|> Flow.reduce(fn -> %{} end, fn word, map ->\nMap.update(map, word, 1, & &1 + 1)\nend)\n|> Enum.into(%{})\n<\/code><\/pre>\n

Don’t worry about the details of the example above for now. We will revisit it in future posts.<\/p>\n

Next steps<\/h2>\n

In the next article, we will talk about lazy computations and async streams, which provide some useful background before jumping into Flow<\/code>. If you would like to get a head start, watch my keynote about GenStage & Flow at ElixirConf<\/a> and read the excellent documentation of the Flow project<\/a>.<\/p>\n


\n\"Subscribe
\n<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

This is the first article in a series of articles about “small data” (in contrast to “big data”) in Elixir. We will start by defining what is “small data”, why it matters and then briefly describe the Flow tool and what to expect in the next articles of the series. How small is small? We … \u00bb<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[143,256],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/6185"}],"collection":[{"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/comments?post=6185"}],"version-history":[{"count":11,"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/6185\/revisions"}],"predecessor-version":[{"id":6271,"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/6185\/revisions\/6271"}],"wp:attachment":[{"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/media?parent=6185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/categories?post=6185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/tags?post=6185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}