Note that there are some explanatory texts on larger screens.

plurals
  1. POPoor performance of reads in pthreads hash table using read-write locks
    primarykey
    data
    text
    <p>I've put together a simple key value store which speaks a subset of the <a href="http://redis.io/" rel="nofollow">Redis</a> protocol. It uses pthreads on Linux to share the hash table; I use pthreads rwlocks to manage access to this table. I've been testing the K-V store using the Redis benchmark tool.</p> <p>With a single client, I can do about 2500 SET operations a second. However, it can only do about 25 GETs per second; I'd expect the other way around, so this surprises me. It scales to some extent, so if I throw 10 clients at it I'll get nearly 9000 SETs per second and around 250 GETs per second.</p> <p>My GET code is pretty simple; I lock the table, find the appropriate hash table location, and check for a matching key in the linked-list there. For a GET, I use <code>pthread_rwlock_rdlock</code> and <code>pthread_rwlock_unlock</code> when I'm done. For SET, I use <code>pthread_rwlock_wrlock</code> and <code>pthread_rwlock_unlock</code>. SET is quite a bit more complex than GET.</p> <p>I also made the code work on Plan 9, using shared-memory processes and their own implementation of read/write locks. There, GETs are almost as fast as SETs, instead of 100x slower. This makes me think my hash table code is probably ok; I use exactly the same hash table code for both OSes, I simply use #defines to select the appropriate lock for each OS (the interface is the same in both cases, lucky!).</p> <p>I'm not very experienced with pthreads. Can anyone help me figure out why my performance is sucking so badly?</p> <p>(Note: this isn't meant to be a high-performing K-V store, it's meant to be a naively written test application/benchmark. It handles requests in about the simplest method possible, by spinning off a new thread for every client)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload