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.

(Nio|Epoll)EventLoop.pendingTasks should not block when called outside of event loop

See original GitHub issue

Expected behavior

EventLoop.pendingTasks should be (reasonably) cheap to invoke so it can be used within observability.

Actual behavior

We’ve been experimenting with overriding EventExecutorChooserFactory with more superior load balancing algorithms and found out that it might be quite non-trivial to support pending-tasks load metric (pick the least loaded event loop).

After poking around the code, it seems when querying pendingTasks of either NioEventLoop or EpollEventLoop, the method blocks if called outside of said event loop. Put it this way, it’s only cheap to query event loop’s pending tasks from within the same event loop. Perhaps I miss some (historical) context for pendingTask, but for an uneducated reader, it just defeats the purpose of a method providing visibility into an event loop.

I was hoping to pick up some context on the current behavior of pendingTasks and see if we ever want/will to change it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:24 (24 by maintainers)

github_iconTop GitHub Comments

2reactions
nitsanwcommented, Aug 16, 2018

@johnou I apologize if I sounded impatient 😃 I was reading your question from the GitHub email. Here’s what I got:

@nitsanw is it safe to invoke MpscQueue.size() from multiple threads?

It appears that further edits do not get sent as further e-mails.

So, yes, it’s safe to call size on any queue in jctools from any thread, no issue. Furthermore, current queue being used is either the MpscChunkedArrayQueue or MpscUnboundedArrayQueue: https://github.com/netty/netty/blob/06f3574e46e0623a45a93d36dbe7aa3d7455a995/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L823

Both of which have a very fast size() method.

As a side note, I’m not sure why in the non-unsafe case you do not use MpscChunkedAtomicArrayQueue: https://github.com/netty/netty/blob/06f3574e46e0623a45a93d36dbe7aa3d7455a995/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L859

Thanks

1reaction
johnoucommented, Aug 16, 2018

@nitsanw and also asked if it was unsafe and posed risks ie. livelock, but given your comment now I will assume it’s safe to invoke size() from multiple threads, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Don't Block the Event Loop (or the Worker Pool) - Node.js
Abstractly, the Event Loop and the Worker Pool maintain queues for pending events and pending tasks, respectively. In truth, the Event Loop does...
Read more >
Nodejs Event Loop System: A Hand's On Approach — Part 1
In this first post, We will look into the basic details of IO operations (Non-blocking and blocking), libuv, event loop, and Node.js, ...
Read more >
Event Loop and the Big Picture — NodeJS Event Loop Part 1
If there are no events in the event queue or the Event Demultiplexer has no pending requests, the program will complete.
Read more >
How the single threaded non blocking IO model works in ...
You can think of node's event loop as somewhat similar to the kernel's dispatcher: the kernel would schedule for execution a blocked thread...
Read more >
libev - a high performance full-featured event loop written in C
Note that this function is not thread-safe, so if you want to use it from multiple threads, you have to employ some kind...
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