From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Vladimir Davydov <vdavydov@tarantool.org>, tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} in C Date: Mon, 2 Aug 2021 23:49:51 +0200 [thread overview] Message-ID: <9dbecb42-b2c8-ff46-ef1c-c8c14f19357f@tarantool.org> (raw) In-Reply-To: <5bc68e715031c04ebb022c70cf4ff27c0939598c.1627024646.git.vdavydov@tarantool.org> Thanks for working on this! See 3 comments below. > diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c > index e88db6323afa..12d82738a050 100644 > --- a/src/box/lua/net_box.c > +++ b/src/box/lua/net_box.c > @@ -465,62 +465,45 @@ netbox_decode_greeting(lua_State *L) > * interaction. > */ > static int > -netbox_communicate(lua_State *L) > +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. > { > - uint32_t fd = lua_tonumber(L, 1); > const int NETBOX_READAHEAD = 16320; > - struct ibuf *send_buf = (struct ibuf *) lua_topointer(L, 2); > - struct ibuf *recv_buf = (struct ibuf *) lua_topointer(L, 3); > - > - /* limit or boundary */ > - size_t limit = SIZE_MAX; > - const void *boundary = NULL; > - size_t boundary_len; > - > - if (lua_type(L, 4) == LUA_TSTRING) > - boundary = lua_tolstring(L, 4, &boundary_len); > - else > - limit = lua_tonumber(L, 4); > - > - /* timeout */ > - ev_tstamp timeout = TIMEOUT_INFINITY; > - if (lua_type(L, 5) == LUA_TNUMBER) > - timeout = lua_tonumber(L, 5); > if (timeout < 0) { > - lua_pushinteger(L, ER_TIMEOUT); > - lua_pushstring(L, "Timeout exceeded"); > - return 2; > + diag_set(ClientError, ER_TIMEOUT); > + return -1; > } > int revents = COIO_READ; > while (true) { > /* reader serviced first */ > check_limit: > if (ibuf_used(recv_buf) >= limit) { > - lua_pushnil(L); > - lua_pushinteger(L, (lua_Integer)limit); > - return 2; > + *limit_or_boundary_pos = limit; > + return 0; > } > const char *p; > if (boundary != NULL && (p = memmem( > recv_buf->rpos, > ibuf_used(recv_buf), > boundary, boundary_len)) != NULL) { > - lua_pushnil(L); > - lua_pushinteger(L, (lua_Integer)( > - p - recv_buf->rpos)); > - return 2; > + *limit_or_boundary_pos = p - recv_buf->rpos; > + return 0; > } > > while (revents & COIO_READ) { > void *p = ibuf_reserve(recv_buf, NETBOX_READAHEAD); > - if (p == NULL) > - luaL_error(L, "out of memory"); > + if (p == NULL) { > + 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. > diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua > index d7394b088752..0ad6cac022f2 100644 > --- a/src/box/lua/net_box.lua > +++ b/src/box/lua/net_box.lua > @@ -582,46 +581,23 @@ local function create_transport(host, port, user, password, callback, > end > > -- IO (WORKER FIBER) -- > - local function send_and_recv(limit_or_boundary, timeout) > - return communicate(connection:fd(), send_buf, recv_buf, > - limit_or_boundary, timeout) > - end > - > local function send_and_recv_iproto(timeout) > - local data_len = recv_buf.wpos - recv_buf.rpos > - local required > - if data_len < 5 then > - required = 5 > - else > - -- PWN! insufficient input validation > - local bufpos = recv_buf.rpos > - local len, rpos = decode(bufpos) > - required = (rpos - bufpos) + len > - if data_len >= required then > - local body_end = rpos + len > - local hdr, body_rpos = decode(rpos) > - recv_buf.rpos = body_end > - return nil, hdr, body_rpos, body_end > - end > + 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.
next prev parent reply other threads:[~2021-08-02 21:49 UTC|newest] Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-23 11:07 [Tarantool-patches] [PATCH 00/20] Rewrite performance critical parts of net.box " Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 01/20] net.box: fix console connection breakage when request is discarded Vladimir Davydov via Tarantool-patches 2021-07-28 22:49 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 10:40 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 02/20] net.box: wake up wait_result callers " Vladimir Davydov via Tarantool-patches 2021-07-29 10:47 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 03/20] net.box: do not check worker_fiber in request:result, is_ready Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 04/20] net.box: remove decode_push from method_decoder table Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 05/20] net.box: use decode_tuple instead of decode_get Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 06/20] net.box: rename request.ctx to request.format Vladimir Davydov via Tarantool-patches 2021-07-28 22:49 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 10:54 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:39 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 8:15 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 07/20] net.box: use integer id instead of method name Vladimir Davydov via Tarantool-patches 2021-07-28 22:50 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 11:30 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 08/20] net.box: remove useless encode optimization Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 09/20] net.box: rewrite request encoder in C Vladimir Davydov via Tarantool-patches 2021-07-28 22:51 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 14:08 ` Vladimir Davydov via Tarantool-patches 2021-07-29 14:10 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 10/20] lua/utils: make char ptr Lua CTIDs public Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 11/20] net.box: rewrite response decoder in C Vladimir Davydov via Tarantool-patches 2021-07-27 14:07 ` Cyrill Gorcunov via Tarantool-patches 2021-07-27 14:14 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:39 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 8:44 ` Vladimir Davydov via Tarantool-patches 2021-07-30 22:12 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-02 7:36 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 12/20] net.box: rewrite error " Vladimir Davydov via Tarantool-patches 2021-07-30 22:13 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-02 8:00 ` Vladimir Davydov via Tarantool-patches 2021-08-02 21:47 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} " Vladimir Davydov via Tarantool-patches 2021-08-02 21:49 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-08-03 15:44 ` Vladimir Davydov via Tarantool-patches 2021-08-03 23:06 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 13:56 ` Vladimir Davydov via Tarantool-patches 2021-08-04 21:18 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 8:37 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 14/20] net.box: rename netbox_{prepare, encode}_request to {begin, end} Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 15/20] net.box: rewrite request implementation in C Vladimir Davydov via Tarantool-patches 2021-08-02 21:54 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 12:30 ` Vladimir Davydov via Tarantool-patches 2021-08-04 15:35 ` Vladimir Davydov via Tarantool-patches 2021-08-04 16:14 ` Vladimir Davydov via Tarantool-patches 2021-08-04 21:20 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 12:46 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 16/20] net.box: store next_request_id in C code Vladimir Davydov via Tarantool-patches 2021-08-03 23:06 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 16:25 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 17/20] net.box: rewrite console handlers in C Vladimir Davydov via Tarantool-patches 2021-08-03 23:07 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 11:53 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 18/20] net.box: rewrite iproto " Vladimir Davydov via Tarantool-patches 2021-08-03 23:08 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 11:54 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 19/20] net.box: merge new_id, new_request and encode_method Vladimir Davydov via Tarantool-patches 2021-08-03 23:08 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 11:55 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 20/20] net.box: do not create request object in Lua for sync requests Vladimir Davydov via Tarantool-patches 2021-08-03 23:09 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 12:23 ` Vladimir Davydov via Tarantool-patches 2021-07-23 12:48 ` [Tarantool-patches] [PATCH 00/20] Rewrite performance critical parts of net.box in C Vladimir Davydov via Tarantool-patches 2021-07-26 7:26 ` Kirill Yukhin via Tarantool-patches 2021-07-27 9:59 ` Vladimir Davydov via Tarantool-patches 2021-07-28 22:51 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 11:33 ` Vladimir Davydov via Tarantool-patches 2021-07-29 15:23 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:38 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 10:04 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:40 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 8:16 ` Vladimir Davydov via Tarantool-patches 2021-08-03 23:05 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 12:40 ` Vladimir Davydov via Tarantool-patches 2021-08-05 20:59 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-09 11:22 ` Igor Munkin via Tarantool-patches 2021-08-09 11:48 ` Vitaliia Ioffe via Tarantool-patches 2021-08-09 13:56 ` Vladimir Davydov via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=9dbecb42-b2c8-ff46-ef1c-c8c14f19357f@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --cc=vdavydov@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} in C' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox