From 971e05c7d8d73f5178e8c2f7b8b3d7aa88575dc2 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jan 21 2015 05:14:00 +0000 Subject: Randomize preference order before calculating recipients --- diff --git a/python-fmn-consumer-randomize.patch b/python-fmn-consumer-randomize.patch new file mode 100644 index 0000000..1ccde59 --- /dev/null +++ b/python-fmn-consumer-randomize.patch @@ -0,0 +1,52 @@ +From 2aa92ed0dd8004df33b3c6de62b047caa895f96a Mon Sep 17 00:00:00 2001 +From: Ralph Bean +Date: Tue, 20 Jan 2015 09:49:25 -0500 +Subject: [PATCH] Randomize preference list per-thread. + +I'm noticing a weird behavior at FMN after restart. All the threads lock on +each other and do basically zero work as they wait for one of them to query +pkgdb for individual users one after another. Thread #1 queries pkgdb for +ralph's packages and Threads 2-10 all wait for it to be done before moving on +to the next preference to check. + +This should make each thread step through the preferences in a random order +each time. This means that while Thread #1 queries pkgdb for ralph's packages, +Thread #2 will query pkgdb for pingou's packages, and Thread #3 will query +pkgdb for till's packages, ..etc. (Eventually all those package owning +relationships get cached and we stop querying pkgdb). +--- + fmn/consumer/consumer.py | 11 ++++++++++- + 1 file changed, 10 insertions(+), 1 deletion(-) + +diff --git a/fmn/consumer/consumer.py b/fmn/consumer/consumer.py +index 8a05489..21e8de4 100644 +--- a/fmn/consumer/consumer.py ++++ b/fmn/consumer/consumer.py +@@ -1,6 +1,7 @@ + # An example fedmsg koji consumer + + import threading ++import random + + import fedmsg.consumers + import fmn.lib +@@ -164,7 +165,15 @@ class FMNConsumer(fedmsg.consumers.FedmsgConsumer): + # With cache management done, we can move on to the real work. + # Compute, based on our in-memory cache of preferences, who we think + # should receive this message. +- results = fmn.lib.recipients(self.cached_preferences, msg, ++ ++ # First, make a thread-local copy of our shared cached prefs ++ preferences = list(self.cached_preferences) ++ # Shuffle it so that not all threads step through the list in the same ++ # order. This should cut down on competition for the dogpile lock when ++ # getting pkgdb info at startup. ++ random.shuffle(preferences) ++ # And do the real work of comparing every rule against the message. ++ results = fmn.lib.recipients(preferences, msg, + self.valid_paths, self.hub.config) + + # Let's look at the results of our matching operation and send stuff +-- +2.1.0 + diff --git a/python-fmn-consumer.spec b/python-fmn-consumer.spec index 38fb142..2f12b46 100644 --- a/python-fmn-consumer.spec +++ b/python-fmn-consumer.spec @@ -8,7 +8,7 @@ Name: python-fmn-consumer Version: 0.4.4 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Backend worker daemon for Fedora Notifications Group: Development/Libraries @@ -16,6 +16,8 @@ License: LGPLv2+ URL: http://pypi.python.org/pypi/fmn.consumer Source0: http://pypi.python.org/packages/source/f/%{modname}/%{modname}-%{version}.tar.gz +Patch0: python-fmn-consumer-randomize.patch + BuildArch: noarch BuildRequires: python2-devel @@ -43,6 +45,8 @@ This module contains the backend worker daemon for Fedora Notifications. %prep %setup -q -n %{modname}-%{version} +%patch0 -p1 + # Remove bundled egg-info in case it exists rm -rf %{modname}.egg-info @@ -61,6 +65,9 @@ rm -rf %{modname}.egg-info %{python2_sitelib}/%{modname}-%{version}* %changelog +* Wed Jan 21 2015 Ralph Bean - 0.4.4-2 +- Randomize preference order before calculating recipients. + * Fri Jan 16 2015 Ralph Bean - 0.4.4-1 - new version