From 34900140350c11df3e938184a03026395316f54e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 1 Apr 2017 12:05:25 +0100 Subject: [PATCH] [Fix] Do not count sending and loading time in rspamc --- src/client/rspamc.c | 17 +++++++++++------ src/client/rspamdclient.c | 24 +++++++++++++++++------- src/client/rspamdclient.h | 16 +++++++++------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/client/rspamc.c b/src/client/rspamc.c index d58310de6..839fd2ff0 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -324,7 +324,6 @@ struct rspamc_command { struct rspamc_callback_data { struct rspamc_command *cmd; gchar *filename; - gdouble start; }; gboolean @@ -1392,9 +1391,10 @@ rspamc_client_execute_cmd (struct rspamc_command *cmd, ucl_object_t *result, static void rspamc_client_cb (struct rspamd_client_connection *conn, - struct rspamd_http_message *msg, - const gchar *name, ucl_object_t *result, GString *input, - gpointer ud, GError *err) + struct rspamd_http_message *msg, + const gchar *name, ucl_object_t *result, GString *input, + gpointer ud, gdouble start_time, gdouble send_time, + GError *err) { gchar *ucl_out; struct rspamc_callback_data *cbdata = (struct rspamc_callback_data *)ud; @@ -1405,7 +1405,13 @@ rspamc_client_cb (struct rspamd_client_connection *conn, gsize body_len; cmd = cbdata->cmd; - diff = finish - cbdata->start; + + if (send_time > 0) { + diff = finish - send_time; + } + else { + diff = finish - start_time; + } if (execute) { /* Pass all to the external command */ @@ -1526,7 +1532,6 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd, cbdata = g_slice_alloc (sizeof (struct rspamc_callback_data)); cbdata->cmd = cmd; cbdata->filename = g_strdup (name); - cbdata->start = rspamd_get_ticks (); if (cmd->need_input) { rspamd_client_command (conn, cmd->path, attrs, in, rspamc_client_cb, diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c index 4691ce5ec..6ccdce5f5 100644 --- a/src/client/rspamdclient.c +++ b/src/client/rspamdclient.c @@ -41,6 +41,8 @@ struct rspamd_client_connection { struct timeval timeout; struct rspamd_http_connection *http_conn; gboolean req_sent; + gdouble start_time; + gdouble send_time; struct rspamd_client_request *req; struct rspamd_keypair_cache *keys_cache; }; @@ -92,7 +94,9 @@ rspamd_client_error_handler (struct rspamd_http_connection *conn, GError *err) struct rspamd_client_connection *c; c = req->conn; - req->cb (c, NULL, c->server_name->str, NULL, req->input, req->ud, err); + req->cb (c, NULL, c->server_name->str, NULL, + req->input, req->ud, + c->start_time, c->send_time, err); } static gint @@ -110,6 +114,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, if (!c->req_sent) { c->req_sent = TRUE; + c->send_time = rspamd_get_ticks (); rspamd_http_connection_reset (c->http_conn); rspamd_http_connection_read_message (c->http_conn, c->req, @@ -123,7 +128,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, err = g_error_new (RCLIENT_ERROR, msg->code, "HTTP error: %d, %.*s", msg->code, (gint)msg->status->len, msg->status->str); - req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err); + req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, + c->start_time, c->send_time, err); g_error_free (err); return 0; @@ -169,7 +175,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, "Decompression error: %s", ZSTD_getErrorName (r)); req->cb (c, msg, c->server_name->str, NULL, - req->input, req->ud, err); + req->input, req->ud, c->start_time, + c->send_time, err); g_error_free (err); ZSTD_freeDStream (zstream); g_free (out); @@ -191,7 +198,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s", ucl_parser_get_error (parser)); ucl_parser_free (parser); - req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err); + req->cb (c, msg, c->server_name->str, NULL, req->input, + req->ud, c->start_time, c->send_time, err); g_error_free (err); g_free (zout.dst); @@ -204,7 +212,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, err = g_error_new (RCLIENT_ERROR, 500, "Invalid compression method"); req->cb (c, msg, c->server_name->str, NULL, - req->input, req->ud, err); + req->input, req->ud, c->start_time, c->send_time, err); g_error_free (err); return 0; @@ -216,7 +224,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s", ucl_parser_get_error (parser)); ucl_parser_free (parser); - req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err); + req->cb (c, msg, c->server_name->str, NULL, + req->input, req->ud, c->start_time, c->send_time, err); g_error_free (err); return 0; @@ -224,7 +233,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, } req->cb (c, msg, c->server_name->str, ucl_parser_get_object ( - parser), req->input, req->ud, NULL); + parser), req->input, req->ud, c->start_time, c->send_time, NULL); ucl_parser_free (parser); } @@ -425,6 +434,7 @@ rspamd_client_command (struct rspamd_client_connection *conn, req->msg->url = rspamd_fstring_append (req->msg->url, command, strlen (command)); conn->req = req; + conn->start_time = rspamd_get_ticks (); if (compressed) { rspamd_http_connection_write_message (conn->http_conn, req->msg, NULL, diff --git a/src/client/rspamdclient.h b/src/client/rspamdclient.h index 5313bb88b..e5fe64d91 100644 --- a/src/client/rspamdclient.h +++ b/src/client/rspamdclient.h @@ -37,13 +37,15 @@ struct rspamd_http_client_header { * @param err error pointer */ typedef void (*rspamd_client_callback) ( - struct rspamd_client_connection *conn, - struct rspamd_http_message *msg, - const gchar *name, - ucl_object_t *result, - GString *input, - gpointer ud, - GError *err); + struct rspamd_client_connection *conn, + struct rspamd_http_message *msg, + const gchar *name, + ucl_object_t *result, + GString *input, + gpointer ud, + gdouble start_time, + gdouble send_time, + GError *err); /** * Start rspamd worker or controller command -- 2.39.5