- Notifications
You must be signed in to change notification settings - Fork33
Improving threading safety for telemetry#250
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| funstart() { | ||
| if (!enable|| started|| sampleRate==0.0)return | ||
| started=true | ||
| if (!enable|| started.get()|| sampleRate==0.0)return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
if we need atomic onstarted, likely we need it onenable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Started could maybe get away without as well, but enable will in most cases not ever change and there are several checks where if it happens to pass by one check, it will avoid sending later. But mainly I thought it not worth changing the interface and documentation just yet, since enable is the only exposed API.
| var sampleRate:Double | ||
| get()=_sampleRate | ||
| set(value) { | ||
| synchronized(this) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
we should try our best to avoid usingsynchronized since our API is coroutine-based. people could use our API inside a coroutine which causes a suspend function to block.
| m.value= (m.value/ sampleRate).roundToInt() | ||
| sendQueue.add(m) | ||
| } | ||
| val sendQueue:MutableList<RemoteMetric> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
instead of snapshot the whole queue, snapshot the size of the queue and dequeue just for that size should work and that avoid of using synchronized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
That's what the code was doing originally, can probably just make the queueBytes atomic and leave it at that.
| */ | ||
| funstart() { | ||
| if (!enable|| started.get()|| sampleRate==0.0)return | ||
| if (!enable|| started.get()|| sampleRate.get()==0.0)return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should enable be atomic too?
| system.settings?.let { settings-> | ||
| settings.metrics["sampleRate"]?.jsonPrimitive?.double?.let { | ||
| sampleRate= it | ||
| sampleRate.set(it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
if use sovran, sampleRate does not have to be atomic, since sovran serialize the task in the same thread. same thing applies toenable andstarted
No description provided.