From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 8 Oct 2018 22:45:15 +0300 From: Vladimir Davydov Subject: Re: [tarantool-patches] [PATCH v2] iproto: introduce a proxy module. Message-ID: <20181008194515.h5tgx7erp5ryjywp@esperanza> References: <20181002180554.1142-1-sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181002180554.1142-1-sergepetrenko@tarantool.org> To: Serge Petrenko Cc: tarantool-patches@freelists.org List-ID: On Tue, Oct 02, 2018 at 09:05:54PM +0300, Serge Petrenko wrote: > +static void > +proxy_forward_request(struct iproto_connection *con, struct iproto_msg *msg, > + struct proxy_connection *pcon) > +{ > + struct sync_hash_entry *cs = (struct sync_hash_entry *)malloc(sizeof(*cs)); > + cs->sync = msg->header.sync; > + cs->con = con; > + msg->header.sync = ++pcon->sync_ctr; > + struct mh_i64ptr_node_t node = {pcon->sync_ctr, cs}; > + if (mh_i64ptr_put(pcon->sync_hash, &node, NULL, NULL) == > + mh_end(pcon->sync_hash)) { > + diag_set(OutOfMemory, sizeof(node), "malloc", "sync_hash"); > + diag_raise(); > + } > + coio_write_xrow(&pcon->connection.io, &msg->header); > + > + /* > + * After forwarding the request, mark it as read and > + * delete the msg. > + */ > + msg->p_ibuf->rpos += msg->len; > + iproto_msg_delete(msg); > +} > +static int > +proxy_replier_f(va_list ap) > +{ > + struct proxy_connection *pcon = va_arg(ap, struct proxy_connection *); > + > + struct ev_io io; > + coio_create(&io, pcon->connection.io.fd); > + > + while (!fiber_is_cancelled()) { > + struct xrow_header row; > + coio_read_xrow(&io, &pcon->connection.ibuf, &row); > + uint64_t key = row.sync; > + mh_int_t i = mh_i64ptr_find(pcon->sync_hash, key, NULL); > + if (i == mh_end(pcon->sync_hash)) { > + /* > + * Some error. We recieved a reply with sync > + * not corresponding to any connection > + */ > + say_warn("sync recieved from remote instance is not in sync_hash"); > + continue; > + } > + struct mh_i64ptr_node_t *node = mh_i64ptr_node(pcon->sync_hash, i); > + if (row.type != IPROTO_CHUNK) { > + mh_i64ptr_remove(pcon->sync_hash, node, NULL); > + } > + struct sync_hash_entry * cs = (struct sync_hash_entry *)node->val; > + struct iproto_connection *con = cs->con; > + uint64_t sync = cs->sync; > + row.sync = sync; > + free(cs); I may be wrong, but I think that using a hash table for mapping client connection syncs to server connection syncs, like you do here, may hurt performance (think of thousands requests in flight). If we really want to multiplex, I'd rather consider extending xrow_header with something like connection_id. This might need some benchmarking though. > + coio_write_iproto_response(&con->output, &row); > + > + fiber_gc(); > + } > + return 0; > +}