| 8120 | #define LRU_CYCLE_PERIOD 1000 /* 1000 milliseconds. */ |
| 8121 | #define LRU_CYCLE_PIPELINE_SIZE 250 |
| 8122 | static void LRUTestMode(void) { |
| 8123 | redisReply *reply; |
| 8124 | char key[128]; |
| 8125 | long long start_cycle; |
| 8126 | int j; |
| 8127 | |
| 8128 | srand(time(NULL)^getpid()); |
| 8129 | while(1) { |
| 8130 | /* Perform cycles of 1 second with 50% writes and 50% reads. |
| 8131 | * We use pipelining batching writes / reads N times per cycle in order |
| 8132 | * to fill the target instance easily. */ |
| 8133 | start_cycle = mstime(); |
| 8134 | long long hits = 0, misses = 0; |
| 8135 | while(mstime() - start_cycle < LRU_CYCLE_PERIOD) { |
| 8136 | /* Write cycle. */ |
| 8137 | for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++) { |
| 8138 | char val[6]; |
| 8139 | val[5] = '\0'; |
| 8140 | for (int i = 0; i < 5; i++) val[i] = 'A'+rand()%('z'-'A'); |
| 8141 | LRUTestGenKey(key,sizeof(key)); |
| 8142 | redisAppendCommand(context, "SET %s %s",key,val); |
| 8143 | } |
| 8144 | for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++) |
| 8145 | redisGetReply(context, (void**)&reply); |
| 8146 | |
| 8147 | /* Read cycle. */ |
| 8148 | for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++) { |
| 8149 | LRUTestGenKey(key,sizeof(key)); |
| 8150 | redisAppendCommand(context, "GET %s",key); |
| 8151 | } |
| 8152 | for (j = 0; j < LRU_CYCLE_PIPELINE_SIZE; j++) { |
| 8153 | if (redisGetReply(context, (void**)&reply) == REDIS_OK) { |
| 8154 | switch(reply->type) { |
| 8155 | case REDIS_REPLY_ERROR: |
| 8156 | printf("%s\n", reply->str); |
| 8157 | break; |
| 8158 | case REDIS_REPLY_NIL: |
| 8159 | misses++; |
| 8160 | break; |
| 8161 | default: |
| 8162 | hits++; |
| 8163 | break; |
| 8164 | } |
| 8165 | } |
| 8166 | } |
| 8167 | |
| 8168 | if (context->err) { |
| 8169 | fprintf(stderr,"I/O error during LRU test\n"); |
| 8170 | exit(1); |
| 8171 | } |
| 8172 | } |
| 8173 | /* Print stats. */ |
| 8174 | printf( |
| 8175 | "%lld Gets/sec | Hits: %lld (%.2f%%) | Misses: %lld (%.2f%%)\n", |
| 8176 | hits+misses, |
| 8177 | hits, (double)hits/(hits+misses)*100, |
| 8178 | misses, (double)misses/(hits+misses)*100); |
| 8179 | } |
no test coverage detected