Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Process cascaded work immediately #427

Closed
wants to merge 1 commit into from

Conversation

benaadams
Copy link
Contributor

Without waiting for next libuv pass; due to it being added to the _workAdding buffer and having to wait to the next pass to move to the _workRunning buffer to be submitted; which will currently throttle writes to network and handle close speed.

This is to get the events into the libuv loop as early as possible as it determines its sleep time between loops based on pending work. Otherwise end up with a throttled message pump.

Fix for potential regression in #363 due to bug fix.

@benaadams
Copy link
Contributor Author

/cc @halter73

@benaadams benaadams force-pushed the Process-cascaded-work branch from 522cfdf to 4beec24 Compare November 25, 2015 05:02
{
// Queues swapped
wasWork = DoPostWork();
wasWork = DoPostCloseHandle() || wasWork;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it important to call the DoPost methods twice in one iteration? I think it would be cleaner to just double _maxLoops.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with that; then changed to this, didn't add reason :(

I think it was to make sure a minimum of a double loop had always been done and both queues processed in case a task had snuck in; to get the tasks into the Libuv queue as early as possible for lower latency.

libuv-loop

But if it was DoPostWork that added an item to the queue then wasWork should return true so that would be ok as it would do another loop. If wasWork returned false, then DoPostWork and DoPostCloseHandle would both have returned pretty fast so probably wouldn't be anything extra there?

My worry was the libuv loop sleeping (15ms?) because it had nothing to do; however an item sitting in the thread queue ready to go; but missed due to uv_async_send coalescing and blocked on the add behind the lock; but I was probably being over cautious?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think coalescing is an issue since we always call uv_async_send after enqueing to _workAdding. We've verified that calling uv_async_send will not coalesce if it is the first call after the post callback starts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah; will think a while and see if the reason comes to me; else revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually have taken a better approach - have reverted; then will submit another PR if I can come up with a good reason backed by metrics :)

@halter73
Copy link
Member

I think we need to measure this once #363 is in.

@benaadams benaadams force-pushed the Process-cascaded-work branch 3 times, most recently from ea91e1a to 7bd14bd Compare December 4, 2015 08:53
@benaadams benaadams mentioned this pull request Dec 7, 2015
@benaadams benaadams force-pushed the Process-cascaded-work branch from 7bd14bd to d72e6ae Compare December 9, 2015 08:39
Without waiting for next libuv pass

Fix for potential regression in aspnet#363 due to bug fix.
@benaadams
Copy link
Contributor Author

Merged with #363 as is response to that.

@benaadams benaadams closed this Dec 9, 2015
@benaadams benaadams deleted the Process-cascaded-work branch May 10, 2016 11:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants