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

Add support for Elixir language to benchmark code #2

wants to merge 4 commits into
base: master
Jump to file or symbol
Failed to load files and symbols.
+359 −15
Diff settings


Just for now

@@ -0,0 +1,3 @@
@@ -3,46 +3,73 @@
from os import mkdir
from os.path import join
from multiprocessing import cpu_count
from subprocess import Popen, check_output, PIPE
from sys import stdout
import subprocess
# Add check_output; CentOS 6.3 uses Python 2.6, which doesn't have this
if "check_output" not in dir( subprocess ): # duck punch it in!
def f(*popenargs, **kwargs):
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise subprocess.CalledProcessError(retcode, cmd)
return output
subprocess.check_output = f
def popen_args(filename, *args):
Returns the initial popen args for a given Python or Go file.
args = [filename, "--quiet"] + list(args)
if filename.split(".")[-1] == "py":
return ["python"] + args
args = ["--quiet"] + list(args)
lang = filename.split(".")[-1]
if lang == "py":
return ["python", filename] + list(args)
elif lang == "go":
return ["go", "run", filename] + list(args)
elif lang == "exs":
return ["mix", "run"] + list(args)
return ["go", "run"] + list(args)
raise NameError('Unknown extension', lang)
def run_clients(lang, *args):
Runs the test_client program for Python or Go, for the range
from 1 to cpus * 2 as the number of clients, returning the
median messsages per second for each.
if "--redis" not in args:
broker = Popen(popen_args("run_broker.%s" % lang), stderr=PIPE)
args = popen_args("test_client.%s" % lang, *args)
cmd = popen_args("test_client.%s" % lang, *args)
print " ".join(cmd)
broker = None
if lang == "exs":
subprocess.check_output(["mix", "compile"], stderr=subprocess.PIPE)
elif "--redis" not in args:
broker = subprocess.Popen(popen_args("run_broker.%s" % lang), stderr=subprocess.PIPE)
results = []
num_runs = cpu_count() * 2
print " ".join(args)
for clients in range(1, num_runs + 1):
bar = ("#" * clients).ljust(num_runs)
stdout.write("\r[%s] %s/%s " % (bar, clients, num_runs))
out = check_output(args + ["--num-clients=%s" % clients], stderr=PIPE)
out = subprocess.check_output(cmd + ["--num-clients=%s" % clients] + ["--num-seconds=10"], stderr=subprocess.PIPE)
results.append(out.split(" ")[0].strip())
if "--redis" not in args:
if broker is not None:
return results
# All test_client runs and their cli args.
runs = {
"elixir": ["exs"],
"py_redis": ["py", "--redis", "--unbuffered"],
"py_redis_buffered": ["py", "--redis"],
"py_zmq": ["py"],
@@ -52,6 +79,7 @@ def run_clients(lang, *args):
# Consistent graph colours defined for each of the runs.
colours = {
"elixir": "cyan",
"py_redis": "red",
"py_redis_buffered": "green",
"py_zmq": "blue",
@@ -64,7 +92,7 @@ def run_clients(lang, *args):
"two-queues-1": ["py_zmq", "py_redis"],
"two-queues-2": ["py_zmq", "py_redis", "py_redis_buffered"],
"two-queues-3": ["py_zmq", "py_redis", "py_redis_buffered",
"go_zmq", "go_redis"],
"go_zmq", "go_redis", "elixir"],
# Store all results in an output directory.
@@ -82,7 +110,7 @@ def run_clients(lang, *args):
# Generate graphs.
with open("plot.p", "r") as f:
plotfile =
line = '"%s.dat" using ($0+1):1 with lines title "%s" lw 2 lt rgb "%s"'
line = '"output/%s.dat" using ($0+1):1 with lines title "%s" lw 2 lt rgb "%s"'
for name, names in plots.items():
name = output_path(name)
with open(output_path(names[0] + ".dat"), "r") as f:
@@ -91,4 +119,4 @@ def run_clients(lang, *args):
lines = ", ".join([line % (l, l.replace("_", " "), colours[l])
for l in names])
f.write(plotfile % {"name": name, "lines": lines, "clients": clients})
Popen(["gnuplot", name + ".p"], stderr=PIPE)
subprocess.Popen(["gnuplot", name + ".p"], stderr=subprocess.PIPE)
@@ -0,0 +1,35 @@
# install requirements for CentOS
# by Patrick Wyatt
set -e
sudo yum install -y python python-devel
sudo yum install -y zeromq zeromq-devel
sudo yum install -y redis redis-devel
sudo yum install -y gnuplot
# Install pip
mkdir -p install-pip
cd install-pip
curl -O
python /opt/py_virtual
cd ..
rm -rf install-pip
source /opt/py_virtual/bin/activate
pip install pyzmq
pip install redis
pip install hiredis
pip install argparse
# Install go
rm -r /usr/local/go
tar -C /usr/local -xzf go1.0.3.linux-amd64.tar.gz
rm go1.0.3.linux-amd64.tar.gz
go get
go get
export PATH=$PATH:/usr/local/go/bin
@@ -0,0 +1,17 @@
set -e
if [ 'which erl' ]; then
echo Erlang must be installed before elixir; use
exit 1
git clone /opt/elixir
pushd /opt/elixir
make test
export PATH=$PATH:/opt/elixir/bin
@@ -0,0 +1,12 @@
set -e
curl -O
chmod +x kerl
mv kerl /opt/
kerl build R16A_RELEASE_CANDIDATE r16rc
kerl install r16rc /opt/erlang-r16rc
. /opt/erlang-r16rc/activate
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.