From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 6CE0771211; Thu, 5 Aug 2021 15:46:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6CE0771211 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628167588; bh=WcS5WBcM8sfawmqSA4galHaPq8UckWyyMo6uOqGEd+0=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=G+VdzjCoJIQ5SLQ86z/M6+z6P/pFGH8HOqaL2SMDuDQLpmUWezVMTRRcjY6gbHJ+9 g9yv/9CELyHASXYAYyf1TAOtZCpP/20GzzgW8clJ0/VtoTfoLc42lyXXwVd0Q0cuuW EpRa409otoK0eqRZQbBoTm070rLDmdaSQgRECF9M= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 7919370310 for ; Thu, 5 Aug 2021 15:46:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7919370310 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mBclV-0002FE-S1; Thu, 05 Aug 2021 15:46:26 +0300 Date: Thu, 5 Aug 2021 15:46:24 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210805124624.4ecqx2gv66o7if7b@esperanza> References: <903f6291-bab5-985e-f922-042453e4d146@tarantool.org> <20210804123001.3cwudybvkw6dds74@esperanza> <9c390b8d-cbbb-0aa3-b81b-a8e47a36ed09@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9c390b8d-cbbb-0aa3-b81b-a8e47a36ed09@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD906AB4890CDABF0C5CB76CEE71D3E4007182A05F53808504050E2D604060D9A44A7B6A71B7751ADBB73CA8E645E9C09A8F0ED584CD4233DC3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE797F4D2EDC29AFAF7EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E1D2769089B3DFB28638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85CFABC9BE6CAD51619419971132AB38E117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC55B19328CBC4F849A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10F618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A45692FFBBD75A6A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A53B4E9A334A65241B23ED1B3FB6DD13E7B857079CB9B98285D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34E3E1DC0F9BD55309B37501BB3614CD535EB7DAE5ED289701E5EAD0CE615B71BADEDEAD8A552D90DA1D7E09C32AA3244C1079053C864089A287D5C9EEA0C72BE333C9DC155518937FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojh4v93/7HD3XZ2h9QuvDgKw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D9E7AB3E2C715604A4FDA96C4E8B7AFE6274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 15/20] net.box: rewrite request implementation in C X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Wed, Aug 04, 2021 at 11:20:04PM +0200, Vladislav Shpilevoy wrote: > >>> +static int > >>> +netbox_new_request(struct lua_State *L) > >>> +{ > >>> + struct netbox_request *request = lua_newuserdata(L, sizeof(*request)); > >> > >> 9. Does it help perf if the requests are allocated on mempool? > > > > I tried to allocate requests on mempool. To achieve that, we have to > > turn them into C data. It resulted in a performance degradation, see the > > parallel thread: > > It does not necessarily need to be cdata. You can use > lua_newuserdata(L, sizeof(void *)) and store pointers at the requests which > you allocate on mempool. The downside is that there will be +1 dereference for > each access. The upside is that Lua might have optimizations for small userdata > objects. For example, ffi.new() for objects < 128 bytes is order of magnitude > faster than for bigger objects. Something similar might exist for userdata. Tried that - diff is within stdev with the patched version performing slightly worse: CALL performance over 5 runs: KRPS(WALL) : KRPS(PROC) userdata : 312 +- 7 : 542 +- 20 userdata + mempool : 305 +- 2 : 527 +- 11 Here's the patch I used: -- diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index 06e574cdf746..f6dcf1cca920 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -136,6 +136,8 @@ struct netbox_request { struct error *error; }; +struct mempool netbox_request_pool; + static const char netbox_registry_typename[] = "net.box.registry"; static const char netbox_request_typename[] = "net.box.request"; @@ -1346,7 +1348,8 @@ luaT_netbox_registry_reset(struct lua_State *L) static inline struct netbox_request * luaT_check_netbox_request(struct lua_State *L, int idx) { - return luaL_checkudata(L, idx, netbox_request_typename); + return *(struct netbox_request **)luaL_checkudata( + L, idx, netbox_request_typename); } static int @@ -1355,6 +1358,7 @@ luaT_netbox_request_gc(struct lua_State *L) struct netbox_request *request = luaT_check_netbox_request(L, 1); netbox_request_unregister(request); netbox_request_destroy(request); + mempool_free(&netbox_request_pool, request); return 0; } @@ -1611,8 +1615,10 @@ netbox_make_request(struct lua_State *L, int idx, static int netbox_perform_async_request(struct lua_State *L) { - struct netbox_request *request = lua_newuserdata(L, sizeof(*request)); - netbox_make_request(L, 1, request); + struct netbox_request **request_p = lua_newuserdata( + L, sizeof(*request_p)); + *request_p = mempool_alloc(&netbox_request_pool); + netbox_make_request(L, 1, *request_p); luaL_getmetatable(L, netbox_request_typename); lua_setmetatable(L, -2); return 1; @@ -1976,6 +1982,9 @@ netbox_console_loop(struct lua_State *L) int luaopen_net_box(struct lua_State *L) { + mempool_create(&netbox_request_pool, cord_slab_cache(), + sizeof(struct netbox_request)); + lua_pushcfunction(L, luaT_netbox_request_iterator_next); luaT_netbox_request_iterator_next_ref = luaL_ref(L, LUA_REGISTRYINDEX);