[Tarantool-patches] [PATCH] relay: yield explicitly every N sent rows

Serge Petrenko sergepetrenko at tarantool.org
Mon Feb 15 11:45:25 MSK 2021



13.02.2021 01:25, Cyrill Gorcunov пишет:
> On Fri, Feb 12, 2021 at 10:48:49PM +0100, Vladislav Shpilevoy wrote:
>>> diff --git a/src/box/relay.cc b/src/box/relay.cc
>>> index df04f8198..afc57dfbc 100644
>>> --- a/src/box/relay.cc
>>> +++ b/src/box/relay.cc
>>> @@ -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;
>> Relays are in threads. So this variable either should be thread-local,
>> or be in struct relay. Otherwise you get non-atomic updates which may
>> lead to some increments disappearing.
> That's the good catch! Without lock/tls this gonna be completely
> arbritrary updates.

True. My bad I failed to notice this.

>
>> Given that thread-local variable access is not free, I would go for
>> having it in struct relay, but up to you.
> Actually tls access should be as cheap as regular memory access
> except using different base register (iirc %fs on linux). But
> maybe things are changed novadays.

I found some random article regarding tls access cost:
https://software.intel.com/content/www/us/en/develop/blogs/the-hidden-performance-cost-of-accessing-thread-local-variables.html

So it might be not that cheap. However I didn't dive too deep into the 
article.
I decided to implement the counter as relay member for now.

-- 
Serge Petrenko



More information about the Tarantool-patches mailing list