Skip to content

Commit

Permalink
daemon: out-of-order processing for TCP
Browse files Browse the repository at this point in the history
* daemon now processes messages over TCP stream
out-of-order and concurrently
* support for TCP_DEFER_ACCEPT
* support for TCP Fast-Open
* there are now deadlines for TCP for idle/slow
streams (to prevent slowloris; pruning)
* there is now per-request limit on timeouts
(each request is allowed 4 timeouts before bailing)
* faster request closing, unified retry/timeout timers
* rare race condition in timer closing fixed
  • Loading branch information
vavrusa committed May 3, 2016
1 parent e61c48e commit c23edd0
Show file tree
Hide file tree
Showing 12 changed files with 686 additions and 286 deletions.
12 changes: 12 additions & 0 deletions daemon/README.rst
Expand Up @@ -520,6 +520,18 @@ For when listening on ``localhost`` just doesn't cut it.
> net.bufsize()
4096

.. function:: net.tcp_pipeline([len])

Get/set per-client TCP pipeline limit (number of outstanding queries that a single client connection can make in parallel). Default is 50.

Example output:

.. code-block:: lua
> net.tcp_pipeline()
50
> net.tcp_pipeline(100)

Trust anchors and DNSSEC
^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
46 changes: 34 additions & 12 deletions daemon/bindings.c
Expand Up @@ -48,6 +48,13 @@ static int format_error(lua_State* L, const char *err)
return 1;
}

static inline struct worker_ctx *wrk_luaget(lua_State *L) {
lua_getglobal(L, "__worker");
struct worker_ctx *worker = lua_touserdata(L, -1);
lua_pop(L, 1);
return worker;
}

/** List loaded modules */
static int mod_list(lua_State *L)
{
Expand Down Expand Up @@ -302,14 +309,36 @@ static int net_bufsize(lua_State *L)
return 0;
}

/** Set TCP pipelining size. */
static int net_pipeline(lua_State *L)
{
struct worker_ctx *worker = wrk_luaget(L);
if (!worker) {
return 0;
}
if (!lua_isnumber(L, 1)) {
lua_pushnumber(L, worker->tcp_pipeline_max);
return 1;
}
int len = lua_tointeger(L, 1);
if (len < 0 || len > 4096) {
format_error(L, "tcp_pipeline must be within <0, 4096>");
lua_error(L);
}
worker->tcp_pipeline_max = len;
lua_pushnumber(L, len);
return 1;
}

int lib_net(lua_State *L)
{
static const luaL_Reg lib[] = {
{ "list", net_list },
{ "listen", net_listen },
{ "close", net_close },
{ "interfaces", net_interfaces },
{ "bufsize", net_bufsize },
{ "list", net_list },
{ "listen", net_listen },
{ "close", net_close },
{ "interfaces", net_interfaces },
{ "bufsize", net_bufsize },
{ "tcp_pipeline", net_pipeline },
{ NULL, NULL }
};
register_lib(L, "net", lib);
Expand Down Expand Up @@ -599,13 +628,6 @@ int lib_event(lua_State *L)
return 1;
}

static inline struct worker_ctx *wrk_luaget(lua_State *L) {
lua_getglobal(L, "__worker");
struct worker_ctx *worker = lua_touserdata(L, -1);
lua_pop(L, 1);
return worker;
}

/* @internal Call the Lua callback stored in baton. */
static void resolve_callback(struct worker_ctx *worker, struct kr_request *req, void *baton)
{
Expand Down
3 changes: 3 additions & 0 deletions daemon/engine.h
Expand Up @@ -32,6 +32,9 @@
#ifndef QUERY_RATE_THRESHOLD
#define QUERY_RATE_THRESHOLD (2 * MP_FREELIST_SIZE) /**< Nr of parallel queries considered as high rate */
#endif
#ifndef MAX_PIPELINED
#define MAX_PIPELINED 100
#endif

/*
* @internal These are forward decls to allow building modules with engine but without Lua.
Expand Down

0 comments on commit c23edd0

Please sign in to comment.