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

Do not use synchronised checks during event processing #363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jimilian
Copy link
Contributor

@Jimilian Jimilian commented May 16, 2018

Using synchronised checks during event processing leads to contention on
GerritWorker threads. Especially if lock is done on ToGerritRunListener.
So, to speed up the processing we need to get rid of
isProjectTriggeredAndIncomplete.

isProjectTriggeredAndIncomplete can be replaced by isTriggered and isBuilding.
That transforms the previos version of check to (isTriggered && isBuilding) || isTriggered.
So, it's absolutely safe to keep isTriggered only.

After that plugin itself does not use isProjectTriggeredAndIncomplete.


Screenshot that shows that we were waiting for 2 minutes to parse 4 events.
screen shot 2018-05-16 at 14 39 40

Using synchronised checks during event processing leads to contention on
GerritWorker threads. Especially if lock is done on ToGerritRunListener.
So, to speed up the processing we need to get rid of
`isProjectTriggeredAndIncomplete`.

`isProjectTriggeredAndIncomplete` can be replaced by `isTriggered` and `isBuilding`.
That transforms the previos version of check to `(isTriggered && isBuilding) || isTriggered`.
So, it's absolutely safe to keep `isTriggered` only.

After that plugin itself does not use `isProjectTriggeredAndIncomplete`.
Parallel triggering of multiple jobs for the same event should not
produce any issues as there is synchronization in onStarted method as
well.

But in same time onTriggered also is part of initial event processing.
That's why it's important to not have a lock here.
@Jimilian Jimilian force-pushed the remove_contention_on_event_processing branch from e922ff2 to 37b2b42 Compare May 18, 2018 14:44
//TODO stop builds for earlier patch-sets on same change.
memory.triggered(event, project);
if (event instanceof GerritEventLifecycle) {
((GerritEventLifecycle)event).fireProjectTriggered(project);
}
//Logging
String name = null;
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this?

@@ -328,18 +332,13 @@ protected void cleanUpGerritCauses(GerritCause firstFound, Run build) {
* @param project the project that will be built.
* @param event the event that caused the build to be scheduled.
*/
public synchronized void onTriggered(Job project, GerritTriggeredEvent event) {
public void onTriggered(Job project, GerritTriggeredEvent event) {
//TODO stop builds for earlier patch-sets on same change.
memory.triggered(event, project);
if (event instanceof GerritEventLifecycle) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a change that might have outside repercussions. The lifecycle listeners might have assumptions about owning the monitor when called (which is normal behavior in most listener cases that I've seen)
But I think I can live with that risk if this change is really needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants