Skip to content

Instantly share code, notes, and snippets.

@theonewolf
Created August 10, 2012 00:03
Show Gist options
  • Select an option

  • Save theonewolf/3309316 to your computer and use it in GitHub Desktop.

Select an option

Save theonewolf/3309316 to your computer and use it in GitHub Desktop.
Boosting libhiredis Throughput with Precompiled Queries
  • 1,000,000 key-value pairs (492 Megabytes in)
  • Keys are 4 byte integers (max 2 Terabyte drive)
  • values are 512-byte /dev/urandom derived random 'sectors'
  • KV pairs expire after 300 seconds
  • redis main-memory usage < 20% (700MB at end of 1 test, not perfect measure)
    • drops down over time as expected (expiring)

1. First Cut, No Optimization

Total Time: 3:02 minutes:seconds
SETEX Time: 122 seconds
GET Time: 60 seconds

SETEX per Record (516 bytes): 122 microseconds
GET Time per Record (516 bytes): 60 microseconds

SETEX Bandwidth: 4 MBps
GET Bandwidth: 8 MBps

SETEX from precomputed file: 74 seconds
SETEX Bandwidth: 6.6 MBps

2. Performance Tweak Redis Server-Side

  • Redis Perf. Tweaks: 1. Logging to /dev/null 2. Turn off snapshotting 3. Turn off active rehashing
SETEX w/ tweaks: 67 seconds
per Record: 67 microseconds
SETEX Bandwidth: 7.3 MBps

3. Switch to block size

  • 125,000 Records
  • Key: 4 byte integer
  • Value: 4096 byte block
SETEX Time: 12 seconds
Per Record: 96 microseconds
Bandwidth: 50 MBps

GET Time: 9 seconds
Per Record: 72 microseconds
Bandwidth: 66 MBps

4. Switched to pre-compiled queries (SETEX, GET)

SETEX at 10 seconds
Per Record: 80 microseconds
Bandwidth: 59.6 MBps

GET at 7 seconds
Per Record: 56 microseconds
Bandwidth: 85 MBps

5. Benefits: Instruction and Data cache usage _much_ more effective

BEFORE

I   refs:      2,925,264,920
I1  misses:        4,626,914
LLi misses:            1,383
I1  miss rate:          0.15%
LLi miss rate:          0.00%

D   refs:      1,219,854,214  (687,694,531 rd   + 532,159,683 wr)
D1  misses:            3,690  (      2,791 rd   +         899 wr)
LLd misses:            2,893  (      2,061 rd   +         832 wr)
D1  miss rate:           0.0% (        0.0%     +         0.0%  )
LLd miss rate:           0.0% (        0.0%     +         0.0%  )

LL refs:           4,630,604  (  4,629,705 rd   +         899 wr)
LL misses:             4,276  (      3,444 rd   +         832 wr)
LL miss rate:            0.0% (        0.0%     +         0.0%  )

AFTER

I   refs:      966,243,670
I1  misses:          1,362
LLi misses:          1,294
I1  miss rate:        0.00%
LLi miss rate:        0.00%

D   refs:      430,101,786  (250,567,919 rd   + 179,533,867 wr)
D1  misses:          3,494  (      2,654 rd   +         840 wr)
LLd misses:          2,809  (      2,034 rd   +         775 wr)
D1  miss rate:         0.0% (        0.0%     +         0.0%  )
LLd miss rate:         0.0% (        0.0%     +         0.0%  )

LL refs:             4,856  (      4,016 rd   +         840 wr)
LL misses:           4,103  (      3,328 rd   +         775 wr)
LL miss rate:          0.0% (        0.0%     +         0.0%  )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment