Skip to content

Unnecessary thread synchronization in RequestLoadSimulator?#4

Open
ams-tschoening wants to merge 1 commit intojohnrjenson:masterfrom
ams-tschoening:no_locking
Open

Unnecessary thread synchronization in RequestLoadSimulator?#4
ams-tschoening wants to merge 1 commit intojohnrjenson:masterfrom
ams-tschoening:no_locking

Conversation

@ams-tschoening
Copy link
Copy Markdown

This has already been "mentioned" in #2, but I think is worth some more discussion: Maybe I'm missing something, but in RequestLoadSimulator you are counting the successfully processed requests and use locking on the class itself for that. The number of successfully processed requests seems to be only used as an abort condition.

I think this is unnecessary, because "ExecutorService.invokeAll" is already defined to only return in case all threads successfully finished to provide their results.

Executes the given tasks, returning a list of Futures holding their status and results when all complete. Future.isDone() is true for each element of the returned list.

https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html#invokeAll(java.util.Collection)

We don't care about those results, though, but can simply remove the callback, locking and abort condition loop entirely. While the loop doesn't influence the runtime too much, the locking for incrementing the counter does have a higher negative impact.

During my executions of the same test with/without locking the results were pretty widespread, but without all the locking they were always larger than with.

…ld be unnecessary because "invokeAll" returns only after all work has been done. The used locking to count reduced performance unnecessarily.
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.

1 participant