Skip to content

Commit a96e476

Browse files
author
Tim Watson
committed
udpate managedprocess tutorial with performance notes
1 parent 7e15346 commit a96e476

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

_layouts/managedprocess.html

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<li><a href="#making_use_of_async"><i class="icon-chevron-right"></i> Making use of Async</a></li>
2828
<li><a href="#wiring_up_handlers"><i class="icon-chevron-right"></i> Wiring up handlers</a></li>
2929
<li><a href="#putting_it_all_together"><i class="icon-chevron-right"></i> Putting it all together</a></li>
30+
<li><a href="#performance_considerations"><i class="icon-chevron-right"></i> Performance Considerations</a></li>
3031
</ul>
3132
</div>
3233
</div>

tutorials/3.managedprocess.md

+21
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,24 @@ Hopefully this has demonstrated a few benefits of the `ManagedProcess` API, alth
353353
it's really just scratching the surface. We have focussed on the code that matters -
354354
state transitions and decision making, without getting bogged down (much) with receiving
355355
or sending messages, apart from using some simple APIs when we needed to.
356+
357+
### Performance Considerations
358+
359+
We did not take much care over our choice of data structures. Might this have profound
360+
consequences for clients? The LIFO nature of the pending backlog is surprising, but
361+
we can change that quite easily by changing data structures.
362+
363+
What's perhaps more of a concern is the cost of using `Async` everywhere - remember
364+
we used this in the *server* to handle concurrently executing tasks and obtaining
365+
their results. The `Async` module is also used by `ManagedProcess` to handle the
366+
`call` mechanism, and there *are* some overheads to using it. An invocation of
367+
`async` will create two new processes: one to perform the calculation and another
368+
to monitor the first and handle failure and/or cancellation. Spawning processes is
369+
cheap, but not free as each process is a haskell thread, plus some additional book
370+
keeping data.
371+
372+
The cost of spawning two processes for each computation/task might represent just that
373+
bit too much overhead for some applications. In our next tutorial, we'll look at the
374+
`Control.Distributed.Process.Platform.Task` API, which looks a lot like `Async` but
375+
manages exit signals in a single thread and makes configurable task pools and task
376+
supervision strategy part of its API.

0 commit comments

Comments
 (0)