From: nobu@... Date: 2019-01-17T00:18:07+00:00 Subject: [ruby-core:91135] [Ruby trunk Bug#15438] Threads can't switch faster than TIME_QUANTUM_(NSEC|USEC|MSEC) Issue #15438 has been updated by nobu (Nobuyoshi Nakada). sylvain.joyeux (Sylvain Joyeux) wrote: > Here's the patch for 2.6. I would be glad if you could consider also applying the other patch to 2.5. Thank you so much. In thread_win32.c: ```diff -#define TIME_QUANTUM_USEC (10 * 1000) +#define TIME_QUANTUM_USEC_BASE (100 * 1000) ``` Why 10 times? ```diff +#define TIME_QUANTUM_USEC TIME_QUANTUM_USEC ``` `_BASE` is missing at the last? ```diff +static const rb_hrtime_t TIME_QUANTUM_NSEC = &TIME_QUANTUM_USEC * 1000; ``` The address of a lvalue is invalid, and the multiplication too. Just `&` isn't needed? sylvain.joyeux (Sylvain Joyeux) wrote: > Quick question ... what is the preferred method to provide patches now ? I'm seeing that there are PR on GitHub ... Should I propose the patch here instead ? Anywhere you like. ---------------------------------------- Bug #15438: Threads can't switch faster than TIME_QUANTUM_(NSEC|USEC|MSEC) https://bugs.ruby-lang.org/issues/15438#change-76366 * Author: sylvain.joyeux (Sylvain Joyeux) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- Thread#priority can be set to negative values, which when looking at the code is meant to reduce the time allocated to the thread. However, as far as I could understand in the codebase, the quantum of time is definitely hard-coded to 100ms (TIME_QUANTUM_...). This means that the "lower allocated time" would only work for threads that would often yield one way or the other (sleep, blocking calls, ...) My projects would definitely benefit from a faster switching period. I was wondering how best to implement this ability ? I thought of the following: 1. globally using an environment variable 2. globally using an API 3. trying to adapt dynamically, using the highest needed period 4. lowering the period when a priority lower than 0 is set, leaving it at the lower period. Obviously (3) would seem to be the best, but I'm not sure I would be able to get it right in a decent amount of time. (4) seem to be a good trade-off between simplicity and performance (nothing changes if you never use priorities lower than 0, and if you were you basically get what you wanted). What do you think ? ---Files-------------------------------- 0001-dynamically-modify-the-timer-thread-period-to-accoun.patch (3.12 KB) 0001-2.6-fix-handling-of-negative-priorities.patch (8.43 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: