Francesco Romani has uploaded a new change for review.
Change subject: WIP perf: vdsm/virt/{guestagent,vmchannels}.py
......................................................................
WIP perf: vdsm/virt/{guestagent,vmchannels}.py
DONTMERGE
throw-away unpolished scripts and test data.
Change-Id: I29265e0e077a9267e07448935d05fed9c52a98e6
Signed-off-by: Francesco Romani <[email protected]>
---
M tests/Makefile.am
A tests/guestagentPerf.py
A tests/run_perf.sh
3 files changed, 146 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/04/36304/1
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 930dcbe..dc72428 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -100,17 +100,20 @@
EXTRA_DIST = \
crossImportsTests.py.in \
+ guestagentPerf.py \
makecert.sh \
$(NULL)
dist_noinst_DATA = \
+ ga_msgs.txt.gz \
server.crt \
server.csr \
server.key \
other.crt \
other.csr \
other.key \
- run_tests_local.sh
+ run_tests_local.sh \
+ run_perf.sh
dist_vdsmtests_DATA = \
README \
diff --git a/tests/guestagentPerf.py b/tests/guestagentPerf.py
new file mode 100755
index 0000000..e733912
--- /dev/null
+++ b/tests/guestagentPerf.py
@@ -0,0 +1,136 @@
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import argparse
+import gzip
+import logging
+import threading
+import time
+
+from virt import guestagent
+
+logging.addLevelName(5, 'TRACE')
+logging.TRACE = 5 # impolite but helpful
+
+
+def read_data(name):
+ data, count = [], 0
+ with gzip.GzipFile(name) as src:
+ buf = []
+ for line in src:
+ if line != '\n':
+ buf.append(line)
+ count += 1
+ else:
+ data.append(''.join(buf))
+ buf = []
+ return data, count
+
+
+def guestAgentBench(name='ga_msgs.txt.gz'):
+ log = logging.getLogger('GuestAgent.Bench') # FIXME
+ log.setLevel(logging.INFO)
+ ch = logging.StreamHandler()
+ ch.setLevel(logging.INFO)
+ log.addHandler(ch)
+
+ data, count = read_data(name)
+
+ ga = guestagent.GuestAgent(None, None, log)
+ ga._stopped = False
+ ga._clearReadBuffer()
+
+ start_ts = time.time()
+ for msg in data:
+ ga._handleData(msg)
+ elapsed = time.time() - start_ts
+
+ print 'processed %i messages in %i blocks in %.6f seconds' % (
+ count, len(data), elapsed)
+ print '%.3f messages/second' % (
+ count/elapsed)
+ print 'per-message average time: %.6f seconds' % (
+ elapsed/float(count))
+
+
+def ioworker():
+ while True:
+ with open('/usr/share/dict/words') as src:
+ sum(len(line) for line in src)
+
+
+def cpuworker():
+ while True:
+ res = 0
+ for i in xrange(1000000):
+ res += i
+
+
+def idle():
+ while True:
+ time.sleep(1)
+
+
+def _main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-i", "--idle-threads",
+ type=int, default=0,
+ help="number of idle threads")
+ parser.add_argument("-c", "--cpu-bound-threads",
+ type=int, default=0,
+ help="number of cpu-bound threads")
+ parser.add_argument("-I", "--io-bound-threads",
+ type=int, default=0,
+ help="number of I/O-bound threads")
+ args = parser.parse_args()
+
+ print (
+ "will start"
+ " %i idle threads,"
+ " %i cpu bound threads,"
+ " %i I/O bound threads" % (
+ args.idle_threads,
+ args.cpu_bound_threads,
+ args.io_bound_threads))
+
+ workers = []
+
+ def _setup(th):
+ th.daemon = True
+ workers.append(th)
+
+ for n in xrange(args.idle_threads):
+ _setup(threading.Thread(target=idle))
+ for n in xrange(args.cpu_bound_threads):
+ _setup(threading.Thread(target=cpuworker))
+ for n in xrange(args.io_bound_threads):
+ _setup(threading.Thread(target=ioworker))
+
+ print "threads created"
+ for w in workers:
+ w.start()
+
+ print "threads started"
+ guestAgentBench()
+
+
+if __name__ == '__main__':
+ _main()
diff --git a/tests/run_perf.sh b/tests/run_perf.sh
new file mode 100755
index 0000000..093b604
--- /dev/null
+++ b/tests/run_perf.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+if [ -z "$PYTHON_EXE" ]; then
+ PYTHON_EXE="/usr/bin/python"
+fi
+
+PYTHONDONTWRITEBYTECODE=1 LC_ALL=C
PYTHONPATH="../lib:../vdsm:../client:../vdsm_api:$PYTHONPATH" "$PYTHON_EXE" $@
--
To view, visit http://gerrit.ovirt.org/36304
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I29265e0e077a9267e07448935d05fed9c52a98e6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches