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

Workaround race contition in drawer.redrawMetrics() #112

Closed

Conversation

fedorlitau
Copy link
Contributor

This is my current workaround I am using for the issue #111 (fatal error: concurrent map iteration and map write) to guard against concurrent access to the shared map StatusCodes accross ali and its library tsenart/vegeta

@fedorlitau fedorlitau force-pushed the workaround-racecondition-map branch from 49e1cbb to 8deac8f Compare September 4, 2021 09:38
@nakabonne
Copy link
Owner

nakabonne commented Sep 6, 2021

@fedorlitau Thank you for your discovery. The cause is definitely the data race on the StatusCode 👍

Your workaround solution is correct. It should perform correctly. But I have an idea that is simpler and goroutines don't block each other.
How about copying the StatusCode map when making a new Metrics (ali/attacker/metrics.go#L71) like:

 }

 func newMetrics(m *vegeta.Metrics) *Metrics {
+       codes := make(map[string]int, len(m.StatusCodes))
+       for k, v := range m.StatusCodes {
+               codes[k] = v
+       }
        return &Metrics{
                Latencies: LatencyMetrics{
                        Total: m.Latencies.Total,
@@ -98,7 +102,7 @@ func newMetrics(m *vegeta.Metrics) *Metrics {
                Rate:        m.Rate,
                Throughput:  m.Throughput,
                Success:     m.Success,
-               StatusCodes: m.StatusCodes,
+               StatusCodes: codes,
                Errors:      m.Errors,
        }
 }

The StatusCode map never gets huge, so the complexity of copying will be not that much.

@fedorlitau
Copy link
Contributor Author

@nakabonne I'm glad I could point into the right direction =) I like the copy idea, because it also decouples ali's type Metrics from vegeta's more 👍

@nakabonne
Copy link
Owner

@fedorlitau Thank you. If you don't mind, could you work on that solution? Possibly, the above change will work well.

@fedorlitau
Copy link
Contributor Author

Hey @nakabonne, sorry for the delay - I have created a new PR #115. Haven't tested it for hours, but first tests look good - no crashes.

@fedorlitau fedorlitau closed this Sep 14, 2021
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

Successfully merging this pull request may close these issues.

2 participants