Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
MichaelGHSeg wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromMichaelGHSeg/telemetry_threading_cleanup

Conversation

@MichaelGHSeg
Copy link
Contributor

No description provided.

funstart() {
if (!enable|| started|| sampleRate==0.0)return
started=true
if (!enable|| started.get()|| sampleRate==0.0)return
Copy link
Contributor

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

Copy link
ContributorAuthor

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) {
Copy link
Contributor

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>
Copy link
Contributor

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

Copy link
ContributorAuthor

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.

@MichaelGHSegMichaelGHSeg marked this pull request as draftDecember 4, 2024 15:57
*/
funstart() {
if (!enable|| started.get()|| sampleRate==0.0)return
if (!enable|| started.get()|| sampleRate.get()==0.0)return
Copy link
Contributor

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)
Copy link
Contributor

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@wenxi-zengwenxi-zengwenxi-zeng left review comments

@didiergarciadidiergarciaAwaiting requested review from didiergarcia

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@MichaelGHSeg@wenxi-zeng

[8]ページ先頭

©2009-2025 Movatter.jp