Grumpy tutorial and performance analysis



It is very well known between python developers that performance is not good, but things get worst when a python application uses threads. Global interpreter lock (GIL) is a mutex that prevents multiple native threads from executing Python bytecodes at once. Since today most of processors are multi-core having a GIL is a costly penalty since the cpu can't be used at 100%. One possible solution to this problem is to use multiprocess, python has a standard package called multiprocess that is very easy to use. As many knows using multiprocess has an overhead problem since for communication between processes a serialization and the reverse operation is requried to be done and also there is more overhead at the OS level (more than using threads).

Today Wednesday, January 4 of 2017 google released to the public grumpy which is an experimental Python runtime for Go.

This tutorial requires you to install the go lenguage.

Step 1: Download and install grumpy

We will clone the grumpy code from github and compile it:

git clone https://github.com/google/grumpy.git
cd grumpy

Just a quick test to verify that everything was working

echo "print 'hello, world'" | make run

Step 2: Compile python to GO

Create a python file with some python code:

echo 'print "hello, world"' > hello.py

Export some environment variables to make the toolchain work:

export GOPATH=$PWD/build
export PYTHONPATH=$PWD/build/lib/python2.7/site-packages

You can add those variables to your .bashrc or .zshrc.

Now you are ready to compile:

build/bin/grumpc hello.py > hello.go
go build -o hello hello.go

You will have a new file "hello". Execute it to obtain:

hello, world


Compilation errors

If you get compilations errors, check whcih is your default python interpreter. If it was python 3, switch to python 2 changing your PATH env. variable. Always execute make clean.