[Tarantool-patches] [PATCH] relay: yield explicitly every N sent rows
Serge Petrenko
sergepetrenko at tarantool.org
Fri Feb 12 15:08:51 MSK 2021
12.02.2021 14:37, Cyrill Gorcunov пишет:
> On Fri, Feb 12, 2021 at 02:25:41PM +0300, Serge Petrenko wrote:
>> @@ -836,11 +836,20 @@ relay_send(struct relay *relay, struct xrow_header *packet)
>> {
>> ERROR_INJECT_YIELD(ERRINJ_RELAY_SEND_DELAY);
>>
>> + static uint64_t row_cnt = 0;
>> packet->sync = relay->sync;
>> relay->last_row_time = ev_monotonic_now(loop());
>> coio_write_xrow(&relay->io, packet);
>> fiber_gc();
>>
>> + /*
>> + * It may happen that the socket is always ready for write, so yield
>> + * explicitly every now and then to not block the event loop.
>> + */
>> + row_cnt++;
>> + if (row_cnt % WAL_ROWS_PER_YIELD == 0) {
>> + fiber_sleep(0);
>> + }
> Serge, if I'm not missing something obvious, this row counter is
> related to xstream->rows? So maybe define this type as size_t instead,
Thanks for the review!
Yes, it serves the same purpose.
No problem, let it be size_t, updated.
> to be consistent with another occurence of WAL_ROWS_PER_YIELD. Say,
>
> static size_t row_cnt = 0;
> ...
> if (++row_cnt % WAL_ROWS_PER_YIELD == 0)
> fiber_sleep(0);
>
> I'm fine with uint64_t as well, just out of curiosity.
Looks fine. My bad, I didn't pay enough attention when writing the patch.
=========================================================================
diff --git a/src/box/relay.cc b/src/box/relay.cc
index afc57dfbc..1d8edf116 100644
--- a/src/box/relay.cc
+++ b/src/box/relay.cc
@@ -836,7 +836,7 @@ relay_send(struct relay *relay, struct xrow_header
*packet)
{
ERROR_INJECT_YIELD(ERRINJ_RELAY_SEND_DELAY);
- static uint64_t row_cnt = 0;
+ static size_t row_cnt = 0;
packet->sync = relay->sync;
relay->last_row_time = ev_monotonic_now(loop());
coio_write_xrow(&relay->io, packet);
@@ -846,10 +846,9 @@ relay_send(struct relay *relay, struct xrow_header
*packet)
* It may happen that the socket is always ready for write, so yield
* explicitly every now and then to not block the event loop.
*/
- row_cnt++;
- if (row_cnt % WAL_ROWS_PER_YIELD == 0) {
+ if (++row_cnt % WAL_ROWS_PER_YIELD == 0)
fiber_sleep(0);
- }
+
struct errinj *inj = errinj(ERRINJ_RELAY_TIMEOUT, ERRINJ_DOUBLE);
if (inj != NULL && inj->dparam > 0)
fiber_sleep(inj->dparam);
--
Serge Petrenko
More information about the Tarantool-patches
mailing list