Menu

#74 Re-implement timewait

1.0
open
nobody
None
True
2015-04-29
2015-04-29
No

At present, the timewait threads are scanned for using the walk_all_threads() interface if timewait_threads is non-zero. This means that a single sleeping thread causes the background thread to expend energy polling every thread to see if it is in timewait, and if so, what the waketime is.

It would be more efficient if, when putting a thread to sleep, we calculate the next closest waketime and the background thread does nothing until that time has passed. Obviously if there is already a shorter waketime, then do nothing.

When the time is reached, the background thread needs to scan all threads to see which ones need waking, and to recalculate the next waketime.

Care needs to be taken to ensure that writing this value doesn't cause corruption (multi-byte write and read in background()), but this can be achieved through either a mutex_lock or by disabling kernel preemption when writing it.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB