Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the client is thread safe? #12

Open
hh23485 opened this issue Apr 22, 2020 · 10 comments
Open

If the client is thread safe? #12

hh23485 opened this issue Apr 22, 2020 · 10 comments

Comments

@hh23485
Copy link

hh23485 commented Apr 22, 2020

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?

@vthiery
Copy link
Owner

vthiery commented Apr 22, 2020

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.

@hh23485
Copy link
Author

hh23485 commented Apr 25, 2020

@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?

@vthiery
Copy link
Owner

vthiery commented Apr 25, 2020

@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.

@hh23485
Copy link
Author

hh23485 commented Apr 25, 2020

@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?

@vthiery
Copy link
Owner

vthiery commented Apr 25, 2020

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?

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.

@hh23485
Copy link
Author

hh23485 commented Apr 26, 2020

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?

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.

@vthiery
Copy link
Owner

vthiery commented Jul 21, 2020

@hh23485 have you had any issue related thread-safety? otherwise, I'll close this issue.

@hh23485
Copy link
Author

hh23485 commented Jul 21, 2020

@vthiery Sure, It looks good to me.

@vthiery vthiery closed this as completed Jul 21, 2020
@jakila
Copy link

jakila commented Jan 28, 2022

If you came here because you wonder if this library is thread safe: Please have a look into this later PR: #29
From my understanding that PR does break thread safety, and the statements made earlier in this issues are not true anymore.

@vthiery
Copy link
Owner

vthiery commented Jan 31, 2022

@jakila thanks for pointing that out. I'll re-open this issue and hopefully get some time to investigate it soon

@vthiery vthiery reopened this Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants