Project

General

Profile

Actions

Feature #14757

closed

[PATCH] thread_pthread.c: enable thread cache by default

Added by normalperson (Eric Wong) over 6 years ago. Updated about 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:87030]

Description

Since r62466 ("thread_pthread.c: shorten and fix thread cache implementation"),
our thread cache is no longer buggy with programs using fork.
This makes significant improvements in vm_thread_alive_check1
and vm_thread_create_join benchmarks and does not introduce
regressions.

Unlike old thread cache, I've changed the cache to only last 3
seconds since per-thread setup in most programs rarely takes
more than a few milliseconds to re-establish things like network
connections.  This is configurable by changing the THREAD_CACHE_TIME
variable.

I hope this allows users to simplify their code by removing the
need for thread pools in many cases.

vm_thread_alive_check1 10.872   0.150
vm_thread_close         1.988   2.027
vm_thread_condvar1      0.751   0.767
vm_thread_condvar2      0.744   0.752
vm_thread_create_join   5.296   2.343
vm_thread_mutex1        1.911   1.892
vm_thread_mutex2        1.902   1.896
vm_thread_mutex3        2.389   2.313
vm_thread_pass          0.271   0.272
vm_thread_pass_flood    0.175   0.179
vm_thread_pipe          0.460   0.436
vm_thread_queue         0.453   0.446
vm_thread_sized_queue   0.547   0.547
vm_thread_sized_queue2  1.417   1.413
vm_thread_sized_queue3  1.410   1.426
vm_thread_sized_queue4  0.787   0.791

Speedup ratio: compare with the result of `trunk' (greater is better)
name    built
vm_thread_alive_check1 72.456
vm_thread_close         0.981
vm_thread_condvar1      0.979
vm_thread_condvar2      0.990
vm_thread_create_join   2.260
vm_thread_mutex1        1.010
vm_thread_mutex2        1.003
vm_thread_mutex3        1.033
vm_thread_pass          0.994
vm_thread_pass_flood    0.980
vm_thread_pipe          1.055
vm_thread_queue         1.016
vm_thread_sized_queue   0.999
vm_thread_sized_queue2  1.003
vm_thread_sized_queue3  0.989
vm_thread_sized_queue4  0.995

This seems pretty trivial and low-risk, will commit in a few days
if no objections.


Files

Updated by normalperson (Eric Wong) over 6 years ago

Oops, I forgot to squash the patch and only sent the second part :x
Anyways, it is trivial:

--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -432,7 +432,7 @@ native_thread_destroy(rb_thread_t *th)
}

 #ifndef USE_THREAD_CACHE
-#define USE_THREAD_CACHE 0
+#define USE_THREAD_CACHE 1
 #endif

 #if USE_THREAD_CACHE
Actions #2

Updated by normalperson (Eric Wong) over 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63498.


thread_pthread.c: enable thread cache by default

Since r62466 ("thread_pthread.c: shorten and fix thread cache implementation"),
our thread cache is no longer buggy with programs using fork.
This makes significant improvements in vm_thread_alive_check1
and vm_thread_create_join benchmarks and does not introduce
regressions.

Unlike old thread cache, I've changed the cache to only last 3
seconds since per-thread setup in most programs rarely takes
more than a few milliseconds to re-establish things like network
connections. This is configurable by changing the THREAD_CACHE_TIME
variable.

I hope this allows users to simplify their code by removing the
need for thread pools in many cases.

vm_thread_alive_check1 10.872 0.150
vm_thread_close 1.988 2.027
vm_thread_condvar1 0.751 0.767
vm_thread_condvar2 0.744 0.752
vm_thread_create_join 5.296 2.343
vm_thread_mutex1 1.911 1.892
vm_thread_mutex2 1.902 1.896
vm_thread_mutex3 2.389 2.313
vm_thread_pass 0.271 0.272
vm_thread_pass_flood 0.175 0.179
vm_thread_pipe 0.460 0.436
vm_thread_queue 0.453 0.446
vm_thread_sized_queue 0.547 0.547
vm_thread_sized_queue2 1.417 1.413
vm_thread_sized_queue3 1.410 1.426
vm_thread_sized_queue4 0.787 0.791

Speedup ratio: compare with the result of `trunk' (greater is better)
name built
vm_thread_alive_check1 72.456
vm_thread_close 0.981
vm_thread_condvar1 0.979
vm_thread_condvar2 0.990
vm_thread_create_join 2.260
vm_thread_mutex1 1.010
vm_thread_mutex2 1.003
vm_thread_mutex3 1.033
vm_thread_pass 0.994
vm_thread_pass_flood 0.980
vm_thread_pipe 1.055
vm_thread_queue 1.016
vm_thread_sized_queue 0.999
vm_thread_sized_queue2 1.003
vm_thread_sized_queue3 0.989
vm_thread_sized_queue4 0.995

[ruby-core:87030] [Feature #14757]

Updated by normalperson (Eric Wong) over 6 years ago

ko1 brought up a good point: this may interact badly with
3rd-party libraries which use thread-local storage via
pthread_getspecific/pthread_setspecific (or compiler
extensions).

On one hand, I expected this to be beneficial for malloc
implementations which use thread-specific storage (most all of
them do); but there may be problems in 3rd-party libraries we do
not know about...

So, we might need to disable this before 2.6 release :<

Actions #4

Updated by duerst (Martin Dürst) over 6 years ago

  • Subject changed from [PATCH] thread_pthread.c: enable thread caceh by default to [PATCH] thread_pthread.c: enable thread cache by default

Updated by normalperson (Eric Wong) about 6 years ago

Eric Wong wrote:

ko1 brought up a good point: this may interact badly with
3rd-party libraries which use thread-local storage via
pthread_getspecific/pthread_setspecific (or compiler
extensions).

So, we might need to disable this before 2.6 release :<

ko1 and I agreed this is a low-risk and will keep thread cache
enabled for 2.6. pthread_{get,set}specific isn't very popular
in 3rd-party libraries, or they use it in ways which does
not conflict with thread-caching.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0