Browse Source

Add latency calculations.

tags/0.9.0
Vsevolod Stakhov 9 years ago
parent
commit
4c6b431ae4
1 changed files with 66 additions and 10 deletions
  1. 66
    10
      test/rspamd_http_test.c

+ 66
- 10
test/rspamd_http_test.c View File

#include "ottery.h" #include "ottery.h"
#include "cryptobox.h" #include "cryptobox.h"


static const int file_blocks = 16;
static const int pconns = 100;
static const int ntests = 300;
static const int file_blocks = 8;
static const int pconns = 10;
static const int ntests = 3000;


static void static void
rspamd_server_error (struct rspamd_http_connection_entry *conn_ent, rspamd_server_error (struct rspamd_http_connection_entry *conn_ent,
return 0; return 0;
} }


struct client_cbdata {
double *lat;
struct timespec ts;
};

static void static void
rspamd_client_err (struct rspamd_http_connection *conn, GError *err) rspamd_client_err (struct rspamd_http_connection *conn, GError *err)
{ {
rspamd_client_finish (struct rspamd_http_connection *conn, rspamd_client_finish (struct rspamd_http_connection *conn,
struct rspamd_http_message *msg) struct rspamd_http_message *msg)
{ {
struct client_cbdata *cb = conn->ud;
struct timespec ts;

clock_gettime (CLOCK_MONOTONIC, &ts);
*(cb->lat) = (ts.tv_sec - cb->ts.tv_sec) * 1000. + /* Seconds */
(ts.tv_nsec - cb->ts.tv_nsec) / 1000000.; /* Nanoseconds */
close (conn->fd); close (conn->fd);
rspamd_http_connection_unref (conn); rspamd_http_connection_unref (conn);
g_free (cb);


return 0; return 0;
} }
static void static void
rspamd_http_client_func (const gchar *path, rspamd_inet_addr_t *addr, rspamd_http_client_func (const gchar *path, rspamd_inet_addr_t *addr,
gpointer kp, gpointer peer_kp, struct rspamd_keypair_cache *c, gpointer kp, gpointer peer_kp, struct rspamd_keypair_cache *c,
struct event_base *ev_base)
struct event_base *ev_base, double *latency)
{ {
struct rspamd_http_message *msg; struct rspamd_http_message *msg;
struct rspamd_http_connection *conn; struct rspamd_http_connection *conn;
gchar urlbuf[PATH_MAX]; gchar urlbuf[PATH_MAX];
struct client_cbdata *cb;
gint fd; gint fd;


g_assert ((fd = rspamd_inet_address_connect (addr, SOCK_STREAM, TRUE)) != -1); g_assert ((fd = rspamd_inet_address_connect (addr, SOCK_STREAM, TRUE)) != -1);
msg->peer_key = rspamd_http_connection_key_ref (peer_kp); msg->peer_key = rspamd_http_connection_key_ref (peer_kp);
} }


rspamd_http_connection_write_message (conn, msg, NULL, NULL, NULL,
cb = g_malloc (sizeof (*cb));
clock_gettime (CLOCK_MONOTONIC, &cb->ts);
cb->lat = latency;
rspamd_http_connection_write_message (conn, msg, NULL, NULL, cb,
fd, NULL, ev_base); fd, NULL, ev_base);
} }


static int
cmpd (const void *p1, const void *p2)
{
const double *d1 = p1, *d2 = p2;

return (*d1) - (*d2);
}

double
rspamd_http_calculate_mean (double *lats, double *std)
{
gint i;
gdouble mean = 0., dev = 0.;

qsort (lats, ntests * pconns, sizeof (double), cmpd);

for (i = 0; i < ntests * pconns; i ++) {
mean += lats[i];
}

mean /= ntests * pconns;

for (i = 0; i < ntests * pconns; i ++) {
dev += (lats[i] - mean) * (lats[i] - mean);
}

dev /= ntests * pconns;

*std = sqrt (dev);
return mean;
}

void void
rspamd_http_test_func (void) rspamd_http_test_func (void)
{ {
gint fd, i, j; gint fd, i, j;
pid_t sfd; pid_t sfd;
GString *b32_key; GString *b32_key;
double diff, total_diff = 0.0;
double diff, total_diff = 0.0, latency[pconns * ntests], mean, std;


rspamd_cryptobox_init (); rspamd_cryptobox_init ();
rspamd_snprintf (filepath, sizeof (filepath), "/tmp/http-test-XXXXXX"); rspamd_snprintf (filepath, sizeof (filepath), "/tmp/http-test-XXXXXX");
for (i = 0; i < ntests; i ++) { for (i = 0; i < ntests; i ++) {
for (j = 0; j < pconns; j ++) { for (j = 0; j < pconns; j ++) {
rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr, rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr,
NULL, NULL, c, ev_base);
NULL, NULL, c, ev_base, &latency[i * pconns + j]);
} }
clock_gettime (CLOCK_MONOTONIC, &ts1); clock_gettime (CLOCK_MONOTONIC, &ts1);
event_base_loop (ev_base, 0); event_base_loop (ev_base, 0);
total_diff += diff; total_diff += diff;
} }



msg_info ("Made %d connections of size %d in %.6f ms, %.6f cps", msg_info ("Made %d connections of size %d in %.6f ms, %.6f cps",
ntests * pconns, ntests * pconns,
sizeof (buf) * file_blocks, sizeof (buf) * file_blocks,
total_diff, ntests * pconns / total_diff * 1000.); total_diff, ntests * pconns / total_diff * 1000.);
mean = rspamd_http_calculate_mean (latency, &std);
msg_info ("Latency: %.6f ms mean, %.6f dev",
mean, std);


/* Now test encrypted */ /* Now test encrypted */
b32_key = rspamd_http_connection_print_key (serv_key, b32_key = rspamd_http_connection_print_key (serv_key,
for (i = 0; i < ntests; i ++) { for (i = 0; i < ntests; i ++) {
for (j = 0; j < pconns; j ++) { for (j = 0; j < pconns; j ++) {
rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr, rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr,
client_key, peer_key, c, ev_base);
client_key, peer_key, c, ev_base, &latency[i * pconns + j]);
} }
clock_gettime (CLOCK_MONOTONIC, &ts1); clock_gettime (CLOCK_MONOTONIC, &ts1);
event_base_loop (ev_base, 0); event_base_loop (ev_base, 0);
ntests * pconns, ntests * pconns,
sizeof (buf) * file_blocks, sizeof (buf) * file_blocks,
total_diff, ntests * pconns / total_diff * 1000.); total_diff, ntests * pconns / total_diff * 1000.);
mean = rspamd_http_calculate_mean (latency, &std);
msg_info ("Latency: %.6f ms mean, %.6f dev",
mean, std);


/* Restart server */ /* Restart server */
kill (sfd, SIGTERM); kill (sfd, SIGTERM);
for (i = 0; i < ntests; i ++) { for (i = 0; i < ntests; i ++) {
for (j = 0; j < pconns; j ++) { for (j = 0; j < pconns; j ++) {
rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr, rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr,
client_key, peer_key, c, ev_base);
client_key, peer_key, c, ev_base, &latency[i * pconns + j]);
} }
clock_gettime (CLOCK_MONOTONIC, &ts1); clock_gettime (CLOCK_MONOTONIC, &ts1);
event_base_loop (ev_base, 0); event_base_loop (ev_base, 0);
ntests * pconns, ntests * pconns,
sizeof (buf) * file_blocks, sizeof (buf) * file_blocks,
total_diff, ntests * pconns / total_diff * 1000.); total_diff, ntests * pconns / total_diff * 1000.);
mean = rspamd_http_calculate_mean (latency, &std);
msg_info ("Latency: %.6f ms mean, %.6f dev",
mean, std);


close (fd); close (fd);
unlink (filepath); unlink (filepath);

Loading…
Cancel
Save