Boost logo

Boost Users :

From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2021-02-09 14:56:17


On 09/02/2021 13:19, Dominique Devienne via Boost-users wrote:

> My issue is that Boost.Asio seems to schedule an awful lots of A# and B#
> tasks, before getting to the C# tasks,
> which results in accumulating in memory too many C# tasks, and thus
> using too much memory.
>
> I don't see a way to force more C "downstream" tasks to be scheduled,
> before processing so much A and B tasks,
> and accumulating pending C tasks in the work queue, thus using too much
> memory again.
>
> Could someone please recommend a way to have a more balanced flow of
> tasks in the graph?
> Or alternative designs even, if what I do above is not ideal. Is
> Boost.Asio even suitable in this case?

I think choosing a better framework for your use case would make your
life awfully easier. Grand Central Dispatch works very well on Mac OS
and FreeBSD, and is built into the system. The port of GCD (libdispatch)
to Linux is acceptable. On Windows, you want the Win32 thread pool,
totally different API, but does the same thing.

The difference with GCD like thread pools is firstly that they are
global across the whole system, managed systemically across all
processes by your OS kernel. Secondly, you can assign priority per work
item submitted, so in your case you would assign the highest priority to
the end-most work items, thus ensuring they get selected preferentially
for execution and therefore don't build up in memory. Thirdly, they come
with i/o integration, so there is a highly efficient integration between
your OS i/o reactor and the global whole-system thread pool.

Had ASIO been constructed after these became common, it would
undoubtedly have been designed around them. As it stands, some of us on
WG21 are hoping to target a Networking v2 design which is based around
GCD-type designs for C++ 26 or 29.

You may find the unfinished low level prototype platform abstraction of
these facilities at https://github.com/ned14/llfio/pull/68 useful to
study when designing your own integration. It works well on GCD and
Win32 thread pools. Its native Linux backend is not usable yet. I hope
to send it WG21's way for study before April.

Niall


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net