kunna

kunna

Concurrent Data Processing in Elixir:147

On page 147. the book says “Using Task.async_stream/3 is a great way to process large collections of data, and provide back-pressure at the same time.”

but while using Task.async_stream/3, I found some unexpected memory usages and ran some tests. and my test results show Task.async_stream is not handling back-pressure well. It works fine with fewer concurrency, but it fails to manage the back-pressure when I increased the max_concurrency option to 100.

This is my test code.

defmodule Playground do
  def stream do
    Stream.resource(
      fn -> Enum.to_list(0..100) end,
      fn list ->
        case Enum.split(list, 10) do
          {[], _} ->
            {:halt, []}
          {head, tail} ->
            IO.inspect("emit")
            {head, tail}
        end
      end,
      fn _ -> :foo end
    )
  end

  def run_async do
    stream()
    |> Task.async_stream(__MODULE__, :do_it, [], max_concurrency: 100, ordered: false)
    |> Stream.run()
  end

  def do_it(i) do
    Process.sleep(:rand.uniform(1000))
    IO.inspect(i)
  end
end

and the printed out result

iex(5)> Playground.run_async
"emit"
"emit"
"emit"
"emit"
"emit"
"emit"
"emit"
"emit"
"emit"
"emit"
"emit"
0
51
5
35
52
68
65
21
98
85
87
10
27
29
47
.
.
.
0 817 0

Popular Prag Prog topics Top

Travis
Dockerfile: FROM ruby:2.6 RUN apt-get update -yqq RUN apt-get install -yqq --no-install-recommends nodejs COPY . /usr/src/app/ WORKDI...
7 1193 4
New
jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
10 2605 9
New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
4 981 0
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
15 1541 13
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
4 1174 3
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
0 3894 1
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
0 1101 1
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
0 1481 3
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
8 1083 4
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
0 1143 10
New

Other popular topics Top

Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
36 5142 10
New
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
7 6542 2
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
105 4397 51
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
10 5055 12
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
34 3628 22
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
21 10826 8
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
32 2728 10
New
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
4 3401 2
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
0 2432 1
New

Latest in PragProg

View all threads ❯