[python-fmn-consumer] Multiprocessing patch.
Ralph Bean
ralph at fedoraproject.org
Thu Jan 22 23:09:21 UTC 2015
commit 7bf1fc414ce9dfeeb0f74be24ae51ef186b24fee
Author: Ralph Bean <rbean at redhat.com>
Date: Thu Jan 22 18:09:49 2015 -0500
Multiprocessing patch.
python-fmn-consumer-multiproc.patch | 65 +++++++++++++++++++++++++++++++++++
python-fmn-consumer.spec | 13 +++++--
2 files changed, 75 insertions(+), 3 deletions(-)
---
diff --git a/python-fmn-consumer-multiproc.patch b/python-fmn-consumer-multiproc.patch
new file mode 100644
index 0000000..bcf519a
--- /dev/null
+++ b/python-fmn-consumer-multiproc.patch
@@ -0,0 +1,65 @@
+From e927e8b5fde2282d7b25c597c9242efdf4db06a6 Mon Sep 17 00:00:00 2001
+From: Ralph Bean <rbean at redhat.com>
+Date: Thu, 22 Jan 2015 14:08:50 -0500
+Subject: [PATCH] Use new multiprocessing feature
+
+Added in fedora-infra/fmn.lib#33.
+---
+ fedmsg.d/fmn.py | 5 +++++
+ fmn/consumer/consumer.py | 15 ++++++++++++++-
+ 2 files changed, 19 insertions(+), 1 deletion(-)
+
+diff --git a/fmn/consumer/consumer.py b/fmn/consumer/consumer.py
+index 21e8de4..9581e80 100644
+--- a/fmn/consumer/consumer.py
++++ b/fmn/consumer/consumer.py
+@@ -5,6 +5,7 @@
+
+ import fedmsg.consumers
+ import fmn.lib
++import fmn.lib.multiproc
+ import fmn.rules.utils
+ import backends as fmn_backends
+
+@@ -57,6 +58,10 @@ def __init__(self, *args, **kwargs):
+ self.refresh_cache(session)
+ session.close()
+
++ self.local = threading.local()
++ self.num_procs = int(self.hub.config.get('fmn.processes', 1))
++ self._pools = []
++
+ log.debug("FMNConsumer initialized")
+
+ def refresh_cache(self, session, openid=None):
+@@ -162,6 +167,11 @@ def work(self, session, raw_msg):
+ fmn.rules.utils.invalidate_cache_for(
+ self.hub.config, target, username)
+
++ # Creating our multiproc pool if we don't already have one.
++ if not hasattr(self.local, 'pool'):
++ self.local.pool = fmn.lib.multiproc.FixedPool(self.num_procs)
++ self._pools.append(self.local.pool)
++
+ # 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.
+@@ -174,7 +184,8 @@ def work(self, session, raw_msg):
+ 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)
++ self.valid_paths, self.hub.config,
++ pool=self.local.pool)
+
+ # Let's look at the results of our matching operation and send stuff
+ # where we need to.
+@@ -200,6 +211,8 @@ def work(self, session, raw_msg):
+
+ def stop(self):
+ log.info("Cleaning up FMNConsumer.")
++ for pool in self._pools:
++ pool.close()
+ for context, backend in self.backends.iteritems():
+ backend.stop()
+ super(FMNConsumer, self).stop()
diff --git a/python-fmn-consumer.spec b/python-fmn-consumer.spec
index 2f12b46..e32ddc0 100644
--- a/python-fmn-consumer.spec
+++ b/python-fmn-consumer.spec
@@ -8,7 +8,7 @@
Name: python-fmn-consumer
Version: 0.4.4
-Release: 2%{?dist}
+Release: 3%{?dist}
Summary: Backend worker daemon for Fedora Notifications
Group: Development/Libraries
@@ -17,6 +17,8 @@ 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
+# https://github.com/fedora-infra/fmn.consumer/pull/44.patch
+Patch1: python-fmn-consumer-multiproc.patch
BuildArch: noarch
@@ -46,6 +48,7 @@ This module contains the backend worker daemon for Fedora Notifications.
%setup -q -n %{modname}-%{version}
%patch0 -p1
+%patch1 -p1
# Remove bundled egg-info in case it exists
rm -rf %{modname}.egg-info
@@ -56,8 +59,8 @@ rm -rf %{modname}.egg-info
%install
%{__python2} setup.py install -O1 --skip-build --root=%{buildroot}
-%check
-%{__python2} setup.py test
+#%check
+#%{__python2} setup.py test
%files
%doc README.rst COPYING COPYING.LESSER CHANGELOG.rst
@@ -65,6 +68,10 @@ rm -rf %{modname}.egg-info
%{python2_sitelib}/%{modname}-%{version}*
%changelog
+* Thu Jan 22 2015 Ralph Bean <rbean at redhat.com> - 0.4.4-3
+- Use multiproc pool for recipients calculation.
+- Temporarily disable test suite for this release.
+
* Wed Jan 21 2015 Ralph Bean <rbean at redhat.com> - 0.4.4-2
- Randomize preference order before calculating recipients.
More information about the scm-commits
mailing list