Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use a simple buffer manager for better performance in single core mac…

…hines
  • Loading branch information...
commit 687ae60a2faea719b619266effcf82830ddfc63a 1 parent d4cdcdf
@umago authored
View
8 carbono/buffer_manager/__init__.py
@@ -16,13 +16,19 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
from carbono.buffer_manager.work_manager import WorkManager
+from carbono.buffer_manager.simple_manager import SimpleManager
from carbono.buffer_manager.dummy_manager import DummyManager
+from carbono.utils import *
+
class BufferManagerFactory:
def __init__(self, read_callback, job_callback=None):
if job_callback:
- self._manager = WorkManager(read_callback, job_callback)
+ if available_processors() <= 2 and is_hyperthreading():
+ self._manager = SimpleManager(read_callback, job_callback)
+ else:
+ self._manager = WorkManager(read_callback, job_callback)
else:
self._manager = DummyManager(read_callback)
View
28 carbono/buffer_manager/simple_manager.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+# coding: utf-8
+# Copyright (C) 2011 Lucas Alvares Gomes <lucasagomes@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+from carbono.buffer_manager.dummy_manager import DummyManager
+
+class SimpleManager(DummyManager):
+
+ def __init__(self, read_callback, job_callback):
+ DummyManager.__init__(self, read_callback)
+ self.job = job_callback
+
+ def put(self, data):
+ worked_data = self.job(data)
+ self.output_buffer.put(worked_data)
View
2  carbono/buffer_manager/work_manager.py
@@ -71,7 +71,7 @@ def stop(self):
class WorkManager(Thread):
- def __init__(self, read_callback, job_callback=None):
+ def __init__(self, read_callback, job_callback):
Thread.__init__(self)
self.read_block = read_callback
self.job = job_callback
View
9 carbono/utils.py
@@ -116,6 +116,15 @@ def getinstance():
def available_processors():
return multiprocessing.cpu_count()
+def is_hyperthreading():
+ with open("/proc/cpuinfo", "r") as f:
+ for line in f.readlines():
+ if line.startswith("flags"):
+ if "ht" in line.split():
+ return True
+ break
+ return False
+
def available_memory(percent=100):
free = 0
with open("/proc/meminfo", 'r') as f:
Please sign in to comment.
Something went wrong with that request. Please try again.