Skip to content

fix: Concurrent read,write to a map#467

Merged
kodiakhq[bot] merged 4 commits intomainfrom
fix/concurrent_map_read_write
Dec 7, 2022
Merged

fix: Concurrent read,write to a map#467
kodiakhq[bot] merged 4 commits intomainfrom
fix/concurrent_map_read_write

Conversation

@yevgenypats
Copy link
Copy Markdown
Contributor

Im not sure how we didn't hit this before but I was able to hit this while working on azure number of times. Prob will need another set of eye to make sure it's good now.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 6, 2022

⏱️ Benchmark results

Comparing with 7474c90

  • DefaultConcurrency-2 resources/s: 11,813 ⬇️ 0.03% decrease vs. 7474c90
  • Glob-2 ns/op: 157.4 ⬇️ 19.82% decrease vs. 7474c90
  • BufferedScanner-2 ns/op: 10.15 ⬇️ 14.98% decrease vs. 7474c90
  • LogReader-2 ns/op: 30.65 ⬇️ 18.34% decrease vs. 7474c90

clients = table.Multiplex(client)
}
p.metrics.initWithClients(table, clients)
// p.metrics.initWithClients(table, clients)
Copy link
Copy Markdown
Member

@erezrokah erezrokah Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already called outside the Go routine? Can you share the stack trace of the concurrency error?

I might need to look at this in the morning with fresh 👀

Ah got it, clients already started syncing and accessing metrics, is that the cause?

Maybe it only happens when we have many tables

Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok but will take another look tomorrow morning.
One comment is that maybe we can re-use the clients we generate to avoid calling Multiplex again

@candiduslynx candiduslynx force-pushed the fix/concurrent_map_read_write branch from 52a321c to b2540b1 Compare December 7, 2022 08:09
@kodiakhq kodiakhq bot merged commit ebef24a into main Dec 7, 2022
@kodiakhq kodiakhq bot deleted the fix/concurrent_map_read_write branch December 7, 2022 08:41
Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - this fixes the bug, but introduces another minor one (left a comment)

clients = table.Multiplex(client)
}
p.metrics.initWithClients(table, clients)
// p.metrics.initWithClients(table, clients)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// p.metrics.initWithClients(table, clients)

Let's just remove the line rather?

}
// we do this here to avoid locks so we initial the metrics structure once in the main goroutines
// and then we can just read from it in the other goroutines concurrently given we are not writing to it.
p.metrics.initWithClients(table, clients)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initWithClients recursively traverses the tables, so this still has the (minor) issue that some tables will be initialized twice. Maybe let's add if table.Parent != nil { to the top of this loop for now so that it's correct, and we can clean up/refactor later?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh didn't catch that! Yes, definitely only init parent tables as children will be handled by the initWithClients call.

kodiakhq bot pushed a commit that referenced this pull request Dec 7, 2022
kodiakhq bot pushed a commit that referenced this pull request Dec 7, 2022
🤖 I have created a release *beep* *boop*
---


## [1.11.1](v1.11.0...v1.11.1) (2022-12-07)


### Bug Fixes

* **codegen:** Column type for slices ([7474c90](7474c90))
* Concurrent read,write to a map ([#467](#467)) ([ebef24a](ebef24a))
* **sentry:** Use HTTPSyncTransport, remove flush ([#465](#465)) ([4d48306](4d48306))
* Skip relations when initializing metrics ([#469](#469)) ([5efe564](5efe564))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
erezrokah added a commit to erezrokah/plugin-sdk that referenced this pull request Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants