mirror of
https://github.com/wg/wrk
synced 2025-02-13 22:53:06 +08:00
automatic sampling interval calibration
This commit is contained in:
parent
615b548729
commit
408b4dc4c2
@ -25,6 +25,11 @@ void stats_reset(stats *stats) {
|
||||
stats->max = 0;
|
||||
}
|
||||
|
||||
void stats_rewind(stats *stats) {
|
||||
stats->limit = 0;
|
||||
stats->index = 0;
|
||||
}
|
||||
|
||||
void stats_record(stats *stats, uint64_t x) {
|
||||
stats->data[stats->index++] = x;
|
||||
if (x < stats->min) stats->min = x;
|
||||
|
@ -19,6 +19,7 @@ typedef struct {
|
||||
stats *stats_alloc(uint64_t);
|
||||
void stats_free(stats *);
|
||||
void stats_reset(stats *);
|
||||
void stats_rewind(stats *);
|
||||
|
||||
void stats_record(stats *, uint64_t);
|
||||
|
||||
|
19
src/wrk.c
19
src/wrk.c
@ -288,17 +288,20 @@ static int reconnect_socket(thread *thread, connection *c) {
|
||||
static int calibrate(aeEventLoop *loop, long long id, void *data) {
|
||||
thread *thread = data;
|
||||
|
||||
uint64_t elapsed_ms = (time_us() - thread->start) / 1000;
|
||||
uint64_t req_per_ms = ceil(thread->requests / (double) elapsed_ms);
|
||||
(void) stats_summarize(thread->latency);
|
||||
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->rate = ceil(rate / 10);
|
||||
thread->start = time_us();
|
||||
thread->requests = 0;
|
||||
stats_reset(thread->latency);
|
||||
|
||||
aeCreateTimeEvent(loop, SAMPLE_INTERVAL_MS, sample_rate, thread, NULL);
|
||||
aeCreateTimeEvent(loop, thread->interval, sample_rate, thread, NULL);
|
||||
|
||||
return AE_NOMORE;
|
||||
}
|
||||
@ -316,14 +319,12 @@ static int sample_rate(aeEventLoop *loop, long long id, void *data) {
|
||||
stats_record(statistics.requests, requests);
|
||||
pthread_mutex_unlock(&statistics.mutex);
|
||||
|
||||
uint64_t max = thread->latency->max;
|
||||
thread->missed += missed;
|
||||
thread->requests = 0;
|
||||
thread->start = time_us();
|
||||
stats_reset(thread->latency);
|
||||
thread->latency->max = max;
|
||||
stats_rewind(thread->latency);
|
||||
|
||||
return SAMPLE_INTERVAL_MS;
|
||||
return thread->interval;
|
||||
}
|
||||
|
||||
static int request_complete(http_parser *parser) {
|
||||
|
@ -13,12 +13,11 @@
|
||||
#include "ae.h"
|
||||
#include "http_parser.h"
|
||||
|
||||
#define VERSION "2.2.1"
|
||||
#define VERSION "2.2.2"
|
||||
#define RECVBUF 8192
|
||||
#define SAMPLES 100000000
|
||||
|
||||
#define SOCKET_TIMEOUT_MS 2000
|
||||
#define SAMPLE_INTERVAL_MS 10
|
||||
#define CALIBRATE_DELAY_MS 500
|
||||
#define TIMEOUT_INTERVAL_MS 2000
|
||||
|
||||
@ -34,6 +33,7 @@ typedef struct {
|
||||
pthread_t thread;
|
||||
aeEventLoop *loop;
|
||||
uint64_t connections;
|
||||
int interval;
|
||||
uint64_t stop_at;
|
||||
uint64_t complete;
|
||||
uint64_t requests;
|
||||
|
Loading…
Reference in New Issue
Block a user