�̴߳�������
| 63 | |
| 64 | // �̴߳������� |
| 65 | static void thread_main(void* ctx) |
| 66 | { |
| 67 | char* key = (char*) ctx; |
| 68 | bool (*action_fn)(memcache* conn, const char* key); |
| 69 | string keybuf; |
| 70 | char buf[256]; |
| 71 | |
| 72 | if (__action == "set") |
| 73 | { |
| 74 | action_fn = memcache_set; |
| 75 | memset(__data, 'X', sizeof(__data)); |
| 76 | __data[sizeof(__data) - 1] = 0; |
| 77 | } |
| 78 | else |
| 79 | action_fn = memcache_get; |
| 80 | |
| 81 | struct timeval begin; |
| 82 | gettimeofday(&begin, NULL); |
| 83 | |
| 84 | int i = 0; |
| 85 | for (; i < __loop_count; i++) |
| 86 | { |
| 87 | // �����ӳ��л�ȡһ�� HTTP ���� |
| 88 | memcache* conn = (memcache*) __conn_pool->peek(); |
| 89 | if (conn == NULL) |
| 90 | { |
| 91 | printf("peek connect failed\r\n"); |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | keybuf.format("%s_%d", key, i); |
| 96 | |
| 97 | // ��ʼ�µ� HTTP ������� |
| 98 | if (action_fn(conn, keybuf.c_str()) == false) |
| 99 | { |
| 100 | printf("one request failed, close connection\r\n"); |
| 101 | // ����������Ҫ�ر� |
| 102 | __conn_pool->put(conn, false); |
| 103 | break; |
| 104 | } |
| 105 | else |
| 106 | __conn_pool->put(conn, true); |
| 107 | if (i % 1000 == 0) |
| 108 | { |
| 109 | acl::safe_snprintf(buf, sizeof(buf), "key: %s, action(%s) ok", |
| 110 | keybuf.c_str(), __action.c_str()); |
| 111 | ACL_METER_TIME(buf); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | struct timeval end; |
| 116 | gettimeofday(&end, NULL); |
| 117 | |
| 118 | double spent = util::stamp_sub(&end, &begin); |
| 119 | printf("total: %d, curr: %d, spent: %.2f, speed: %.2f\r\n", |
| 120 | __loop_count, i, spent, (i * 1000) / (spent > 1 ? spent : 1)); |
| 121 | } |
| 122 |
nothing calls this directly
no test coverage detected
searching dependent graphs…