From 35566a8533a7b2ee3260e2dca6d5d487c9efd501 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Fri, 21 Dec 2012 11:50:05 +0100 Subject: [PATCH] start refactoring tcp_info usage --- core/master.c | 33 ++++++++++++++++++++++----------- plugins/python/uwsgi_pymodule.c | 4 ---- uwsgi.h | 3 ++- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/core/master.c b/core/master.c index f0e1dc6b..b5a592d3 100644 --- a/core/master.c +++ b/core/master.c @@ -485,8 +485,9 @@ clear: } -#ifdef __linux__ -int get_linux_tcp_info(int fd) { +int uwsgi_get_tcp_info(int fd) { + +#if defined(__linux__) || defined(__FreeBSD__) socklen_t tis = sizeof(struct tcp_info); if (!getsockopt(fd, IPPROTO_TCP, TCP_INFO, &uwsgi.shared->ti, &tis)) { @@ -495,32 +496,42 @@ int get_linux_tcp_info(int fd) { return -1; } +#if defined(__linux__) uwsgi.shared->load = uwsgi.shared->ti.tcpi_unacked; + uwsgi.shared->max_load = uwsgi.shared->ti.tcpi_sacked; +#elif defined(__FreeBSD__) + uwsgi.shared->load = uwsgi.shared->ti.tcpi_unacked; + uwsgi.shared->max_load = uwsgi.shared->ti.tcpi_sacked; +#endif - uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS] = uwsgi.shared->ti.tcpi_unacked; + + uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS] = uwsgi.shared->load; if (uwsgi.vassal_sos_backlog > 0 && uwsgi.has_emperor) { - if ((int) uwsgi.shared->ti.tcpi_unacked >= uwsgi.vassal_sos_backlog) { + if ((int) uwsgi.shared->load >= uwsgi.vassal_sos_backlog) { // ask emperor for help char byte = 30; if (write(uwsgi.emperor_fd, &byte, 1) != 1) { uwsgi_error("write()"); } else { - uwsgi_log("asking emperor for reinforcements (backlog: %d)...\n", (int) uwsgi.shared->ti.tcpi_unacked); + uwsgi_log("asking emperor for reinforcements (backlog: %d)...\n", (int) uwsgi.shared->load); } } } - if (uwsgi.shared->ti.tcpi_unacked >= uwsgi.shared->ti.tcpi_sacked) { - uwsgi_log_verbose("*** uWSGI listen queue of socket %d full !!! (%d/%d) ***\n", fd, uwsgi.shared->ti.tcpi_unacked, uwsgi.shared->ti.tcpi_sacked); + if (uwsgi.shared->load >= uwsgi.shared->max_load) { + uwsgi_log_verbose("*** uWSGI listen queue of socket %d full !!! (%d/%d) ***\n", fd, uwsgi.shared->load, uwsgi.shared->max_load); uwsgi.shared->options[UWSGI_OPTION_BACKLOG_ERRORS]++; } - return uwsgi.shared->ti.tcpi_unacked; + return uwsgi.shared->load; } +#endif return -1; } + +#ifdef __linux__ #include #ifdef UNBIT @@ -1277,21 +1288,21 @@ health_cycle: check_interval = 1; -#ifdef __linux__ // get listen_queue status struct uwsgi_socket *uwsgi_sock = uwsgi.sockets; while (uwsgi_sock) { if (uwsgi_sock->family == AF_INET) { - uwsgi_sock->queue = get_linux_tcp_info(uwsgi_sock->fd); + uwsgi_sock->queue = uwsgi_get_tcp_info(uwsgi_sock->fd); } +#ifdef __linux__ #ifdef SIOBKLGQ else if (uwsgi_sock->family == AF_UNIX) { uwsgi_sock->queue = get_linux_unbit_SIOBKLGQ(uwsgi_sock->fd); } +#endif #endif uwsgi_sock = uwsgi_sock->next; } -#endif for (i = 1; i <= uwsgi.numproc; i++) { /* first check for harakiri */ diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index e9ba4cb4..a85a265c 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -175,11 +175,7 @@ char *uwsgi_encode_pydict(PyObject * pydict, uint16_t * size) { PyObject *py_uwsgi_listen_queue(PyObject * self, PyObject * args) { -#ifdef __linux__ return PyInt_FromLong(uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS]); -#else - return NULL; -#endif } PyObject *py_uwsgi_close(PyObject * self, PyObject * args) { diff --git a/uwsgi.h b/uwsgi.h index 5697bf8a..cf14f895 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2111,10 +2111,11 @@ struct uwsgi_shared { int worker_log_pipe[2]; -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) struct tcp_info ti; #endif uint64_t load; + uint64_t max_load; struct uwsgi_cron cron[MAX_CRONS]; int cron_cnt;