Skip to content

Avoid creating a thread every single event we receive #11268

Closed

Description

@emilio

We're doing this right now, for some reason I can't understand. We spawn a single thread just to sleep, ensure we're not cancelled, and send an empty message.

If we're going to use threads, we should at least use a thread pool, but probably there's a smarter way to do this, like a single thread that sleeps just the necessary time to dispatch the next event, or something.

I plan to take a look at this, but my time is actually constrained a lot, so if someone wants to investigate and refactor this, please do!

Activity

  1. added
    I-perf-bloat
    I-perf-slow
    A-constellation
    on May 19, 2016
  2. self-assigned this
    on May 19, 2016
  3. asajeffrey commented on May 19, 2016

    @asajeffrey
    Contributor

    I think I can see how to do this fairly easily: we have a dedicated thread for the event queue, which parks itself, then when it is unparked looks to see if the head of the queue is in the past, and if so pops and triggers it, then goes back to being parked. To schedule an event, we just add it to the event queue (in time order) and if we added to the front of the queue, unpark the queue thread.

    Should be a reasonably straightforward use of thread parking and a priority queue, the tricky bit is going to be understanding the current API and if anything depends on the current behaviour.

  4. added 3 commits that reference this issue on May 19, 2016
    c19182a
    17c1ccd
    5b9375a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-constellationI-perf-bloatI-perf-slow

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions