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 8819A6EC58; Tue, 3 Aug 2021 18:44:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8819A6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628005460; bh=x1KL3Vdq7J+ix/GcZm3H31ETGxmjIdq7fWbEAmgmaOg=; 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=cnHKC9oTjSf/ijlhS2zPT1TuAlh7RUHGdw73IgFV6ahdHA/iwcNIpaXCwh09wl1k2 NTFELeWQq+nZwIqW7G6B4TWkW74dQAfisHz01FO4oZS0xrKraDQ25OWsB6XyB3FdU1 oNcDzN9i09kheBbU5xRd6VdXG1Qh2lo3/LN83TV0= 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 269F96EC58 for ; Tue, 3 Aug 2021 18:44:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 269F96EC58 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mAwaY-0006b8-B8; Tue, 03 Aug 2021 18:44:18 +0300 Date: Tue, 3 Aug 2021 18:44:16 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210803154416.3zx5t4jkdyh7adhy@esperanza> References: <5bc68e715031c04ebb022c70cf4ff27c0939598c.1627024646.git.vdavydov@tarantool.org> <9dbecb42-b2c8-ff46-ef1c-c8c14f19357f@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9dbecb42-b2c8-ff46-ef1c-c8c14f19357f@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C351B198F4576AC7B20CA14D9DFB46B94A182A05F5380850408915E54555985786B0DDD55DC0BEB6114FD3EA98B0A5CC340DF4A0C1950A84E1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7484B509D84968742EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637340F95D8C375F5048638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D846AA12C8EC2D6AEBBED965323ACCBD66117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18618001F51B5FD3F9D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A1DCCEB63E2F10FB089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5057FC6E868B16A792B5AF8E2136C8321B1C29BFD126E7493D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA751B940EDA0DFB0535410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342C0B628602DFD0BC4FBF1BE1EE5A6D9C296B99D8CE165E4345CCD127728DD11864FFE5EB40DCE69A1D7E09C32AA3244CA4E365FF15FAB33FB1E6109BE23938753C6EB905E3A8056BFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojeDyvyeZJDJEFi/t6vKbRWg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D2B162084D8A25C73E02CF4828A08F044274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} 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 Mon, Aug 02, 2021 at 11:49:51PM +0200, Vladislav Shpilevoy wrote: > > +netbox_communicate(int fd, struct ibuf *send_buf, struct ibuf *recv_buf, > > + size_t limit, const void *boundary, size_t boundary_len, > > + double timeout, size_t *limit_or_boundary_pos) > > 1. IMO, the name looks really bulky. I would just call it `size` or `end_pos`. > Up to you. Right. Renamed to size. > > + diag_set(OutOfMemory, NETBOX_READAHEAD, > > + "ibuf", "recv_buf"); > > 2. For OutOfMemory errors as a rule we use the format > > diag_set(OutOfMemory, size, "name of the allocation function", > "name of the variable") > > So here it would be > > diag_set(OutOfMemory, NETBOX_READAHEAD, "ibuf_reserve", "p"); > > I know it is violated in a lot of old code and I gave up trying to > enforce it in new patches to exact that form. Up to you. > > The same in the other new OutOfMemory in the other patches. Fixed. > > + local hdr, body_rpos, body_end = internal.send_and_recv_iproto( > > 3. Indexing 'internal' via '.' is not free. It is a lookup > in a hash. You might want to save internal.send_and_recv_iproto into > a global variable when the module loads first time and use the > cached value. Non-cached version is a bit faster only for FFI, but > here you are using Lua C - cache should be good. > > > + connection:fd(), send_buf, recv_buf, timeout) > > Another idea is to cache 'connection:fd()' result into a variable in > the root of create_transport() function. And update it when the > connetion is re-established. Although you probably move this all to > C later as well, I didn't reach the last commits yet. The calling function is moved to C later in the patch set so these comments will become irrelevant. Regarding caching function name (instead of accessing via dot operator), eventually there will be only two hot C functions that could benefit from this: internal.perform_request internal.perform_async_request I tried caching their names, but saw no performance gain at all in my test. I also tried removing fiber_self and fiber_clock aliases from net_box.lua and accessing these functions as fiber. - again no difference. I will do some research about this (try to bench this separately) and add a separate commit to cache the internal function names on top of the series if it helps. Will follow-up in reply to this email. Incremental diff is below. -- diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index cb80d2efa364..6d6d09acafdb 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -437,7 +437,7 @@ netbox_decode_greeting(lua_State *L) /** * Reads data from the given socket until the limit or boundary is reached. - * Returns 0 and sets *limit_or_boundary_pos to limit/boundary_pos on success. + * Returns 0 and sets *size to limit or boundary position on success. * On error returns -1 and sets diag. * * The need for this function arises from not wanting to @@ -452,7 +452,7 @@ netbox_decode_greeting(lua_State *L) static int netbox_communicate(int fd, struct ibuf *send_buf, struct ibuf *recv_buf, size_t limit, const void *boundary, size_t boundary_len, - double timeout, size_t *limit_or_boundary_pos) + double timeout, size_t *size) { const int NETBOX_READAHEAD = 16320; if (timeout < 0) { @@ -464,7 +464,7 @@ netbox_communicate(int fd, struct ibuf *send_buf, struct ibuf *recv_buf, /* reader serviced first */ check_limit: if (ibuf_used(recv_buf) >= limit) { - *limit_or_boundary_pos = limit; + *size = limit; return 0; } const char *p; @@ -472,7 +472,7 @@ check_limit: recv_buf->rpos, ibuf_used(recv_buf), boundary, boundary_len)) != NULL) { - *limit_or_boundary_pos = p - recv_buf->rpos; + *size = p - recv_buf->rpos; return 0; } @@ -480,7 +480,7 @@ check_limit: void *p = ibuf_reserve(recv_buf, NETBOX_READAHEAD); if (p == NULL) { diag_set(OutOfMemory, NETBOX_READAHEAD, - "ibuf", "recv_buf"); + "ibuf_reserve", "p"); return -1; } ssize_t rc = recv(