question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support pluggable EventLoop task queue

See original GitHub issue

The default task queue used by EPoll and NIO EventLoop implementations is provided by JCTools, and while it is efficient it has some undesirable properties. Specifically, it is not non-blocking, and can lead to the EventLoop busy-spinning waiting for a task that may not be provided promptly because the offering thread’s execution has been suspended by the operating system. This is a rare scenario, but it will happen and some application maintainers might like to avoid it.

Unfortunately, there is no simple fix in the use of the queue; the relaxedPoll() method appears to be a candidate, but does not provide volatile visibility guarantees to a preceding offer(), meaning a wakeup could be missed (although we could write to a dummy volatile variable after offering to provide this). A queue identical to the JCTools one but using a putVolatile to set the item in the queue’s backing array would suffice to avoid the busy-spin blocking of the EventLoop, but the issue of future tasks being unreachable until the thread completes would remain.

Ideally, the queue used by these event loops would be pluggable, so that users can choose their ideal point on the spectrum of tradeoffs.

A simple replacement that guarantees progress is the JDK ConcurrentLinkedQueue, but at the cost of slightly more expensive offer() and poll(); the above mentioned modification to the JCTools offer() could be mixed with relaxedPoll() to simply avoid busy-spin blocking, and a custom Mpsc queue implementation could guarantee forward progress with only marginally higher cost. Permitting the application maintainer to pick their poison would be tremendously helpful.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
nitsanwcommented, Aug 19, 2019

@belliottsmith @franz1981 reading through the discussion and the java doc I realize JCTools should do a better job documenting the progress guarantees on this and other queues. I’ve filed a bug: https://github.com/JCTools/JCTools/issues/259

1reaction
belliottsmithcommented, Aug 19, 2019

If this is the issue under discussion, I’m not sure what the following suggestion means: “A queue identical to the JCTools one but using a putVolatile to set the item in the queue’s backing array would suffice to avoid the busy-spin blocking of the EventLoop”

It means the eventLoop (by using relaxedPoll()) would at least be able to proceed with other work such as reading/writing to a socket, or could stop if it had no other work to do, freeing up a thread for the producer to complete its work.

Obviously a preferable solution is to use a truly non-blocking queue, but blocking the eventLoop is worse than just blocking the external work queue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

18.5. asyncio --- Asynchronous I/O, event loop, coroutines and ...
a pluggable event loop with various system-specific implementations; ... coroutines and tasks based on yield from (PEP 380), to help write concurrent code ......
Read more >
Pluggable event loop backends (epoll support) (#693) - GitLab
Create a new class or interface GEventContext, which should become the base for event loop backends, built-in and third-party alike. The ...
Read more >
Event Loop - Apache Samza
The event loop orchestrates reading and processing messages, checkpointing, windowing and flushing metrics among tasks. By default Samza uses a single thread in ......
Read more >
The event loop - JavaScript - MDN Web Docs - Mozilla
The function setTimeout is called with 2 arguments: a message to add to the queue, and a time value (optional; defaults to 0...
Read more >
Async IO in Python: A Complete Walkthrough
Talking to each of the calls to count() is a single event loop, or coordinator. When each task reaches await asyncio.sleep(1) , the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found