1
0
mirror of https://github.com/wg/wrk synced 2026-06-11 02:13:35 +08:00

1 Commits

4 changed files with 19 additions and 12 deletions
+5
View File
@@ -25,6 +25,11 @@ void stats_reset(stats *stats) {
stats->max = 0; stats->max = 0;
} }
void stats_rewind(stats *stats) {
stats->limit = 0;
stats->index = 0;
}
void stats_record(stats *stats, uint64_t x) { void stats_record(stats *stats, uint64_t x) {
stats->data[stats->index++] = x; stats->data[stats->index++] = x;
if (x < stats->min) stats->min = x; if (x < stats->min) stats->min = x;
+1
View File
@@ -19,6 +19,7 @@ typedef struct {
stats *stats_alloc(uint64_t); stats *stats_alloc(uint64_t);
void stats_free(stats *); void stats_free(stats *);
void stats_reset(stats *); void stats_reset(stats *);
void stats_rewind(stats *);
void stats_record(stats *, uint64_t); void stats_record(stats *, uint64_t);
+11 -10
View File
@@ -288,17 +288,20 @@ static int reconnect_socket(thread *thread, connection *c) {
static int calibrate(aeEventLoop *loop, long long id, void *data) { static int calibrate(aeEventLoop *loop, long long id, void *data) {
thread *thread = data; thread *thread = data;
uint64_t elapsed_ms = (time_us() - thread->start) / 1000; (void) stats_summarize(thread->latency);
uint64_t req_per_ms = ceil(thread->requests / (double) elapsed_ms); long double latency = stats_percentile(thread->latency, 90.0) / 1000.0L;
long double interval = MAX(latency * 2, 10);
long double rate = (interval / latency) * thread->connections;
if (!req_per_ms) return CALIBRATE_DELAY_MS / 2; if (latency == 0) return CALIBRATE_DELAY_MS;
thread->rate = (req_per_ms * SAMPLE_INTERVAL_MS) / 10; thread->interval = interval;
thread->start = time_us(); thread->rate = ceil(rate / 10);
thread->start = time_us();
thread->requests = 0; thread->requests = 0;
stats_reset(thread->latency); stats_reset(thread->latency);
aeCreateTimeEvent(loop, SAMPLE_INTERVAL_MS, sample_rate, thread, NULL); aeCreateTimeEvent(loop, thread->interval, sample_rate, thread, NULL);
return AE_NOMORE; return AE_NOMORE;
} }
@@ -316,14 +319,12 @@ static int sample_rate(aeEventLoop *loop, long long id, void *data) {
stats_record(statistics.requests, requests); stats_record(statistics.requests, requests);
pthread_mutex_unlock(&statistics.mutex); pthread_mutex_unlock(&statistics.mutex);
uint64_t max = thread->latency->max;
thread->missed += missed; thread->missed += missed;
thread->requests = 0; thread->requests = 0;
thread->start = time_us(); thread->start = time_us();
stats_reset(thread->latency); stats_rewind(thread->latency);
thread->latency->max = max;
return SAMPLE_INTERVAL_MS; return thread->interval;
} }
static int request_complete(http_parser *parser) { static int request_complete(http_parser *parser) {
+2 -2
View File
@@ -13,12 +13,11 @@
#include "ae.h" #include "ae.h"
#include "http_parser.h" #include "http_parser.h"
#define VERSION "2.2.1" #define VERSION "2.2.2"
#define RECVBUF 8192 #define RECVBUF 8192
#define SAMPLES 100000000 #define SAMPLES 100000000
#define SOCKET_TIMEOUT_MS 2000 #define SOCKET_TIMEOUT_MS 2000
#define SAMPLE_INTERVAL_MS 10
#define CALIBRATE_DELAY_MS 500 #define CALIBRATE_DELAY_MS 500
#define TIMEOUT_INTERVAL_MS 2000 #define TIMEOUT_INTERVAL_MS 2000
@@ -34,6 +33,7 @@ typedef struct {
pthread_t thread; pthread_t thread;
aeEventLoop *loop; aeEventLoop *loop;
uint64_t connections; uint64_t connections;
int interval;
uint64_t stop_at; uint64_t stop_at;
uint64_t complete; uint64_t complete;
uint64_t requests; uint64_t requests;