Open hh23485 opened 4 years ago
Hi!
Unfortunately this client is not thread-safe. Nothing prevents a thread to alter the internal udp sender while another one is already sending metrics.
@vthiery hi, Thanks for your response!
About the un-thread safe client, do you have some suggestions to use it in web project? Or we have to implements a local-free queue as a buffer to a singleton client consumer?
@hh23485 I suppose that, as long as you don't explicitly reconfigure or destroy the client while using it, it will be ok. In the context of a web project, one should first initialize/configure the client, the start spawning threads to treat requests concurrently, and make sure all the requests have been handled before destroying the client.
@vthiery Sure, initialize only once, and destroy the client at the end of the application.
But to be more clear, do you mean, it's safe to call the singleton client's increment
or timing
from multi threads? or I need to do my actions to only one thread call these functions at the same time?
But to be more clear, do you mean, it's safe to call the singleton client's
increment
ortiming
from multi threads? or I need to do my actions to only one thread call these functions at the same time?
It should be. The only sensitive piece is batching (m_batchingMessageQueue
), but I defined a mutex (m_batchingMutex
) and take locks whenever I manipulate the queue.
But to be more clear, do you mean, it's safe to call the singleton client's
increment
ortiming
from multi threads? or I need to do my actions to only one thread call these functions at the same time?It should be. The only sensitive piece is batching (
m_batchingMessageQueue
), but I defined a mutex (m_batchingMutex
) and take locks whenever I manipulate the queue.
That's great, thanks for your explain. I'll test and give a feedback.
Thanks, again.
@hh23485 have you had any issue related thread-safety? otherwise, I'll close this issue.
@vthiery Sure, It looks good to me.
If you came here because you wonder if this library is thread safe: Please have a look into this later PR: https://github.com/vthiery/cpp-statsd-client/pull/29 From my understanding that PR does break thread safety, and the statements made earlier in this issues are not true anymore.
@jakila thanks for pointing that out. I'll re-open this issue and hopefully get some time to investigate it soon
Hi, thanks for the rare cpp statsd client!
We'd like to use the client but my concern is about if the client is thread safe? if not do you have some suggestions to use the client in multi-threads web services?