Inside Mixpanel

Easy backend integration: sending data to Mixpanel in a scalable manner

Suhail Doshi

If you want to log data from your backend, you need to do it in a non-blocking way and you want it to be efficient. You could do it with CURL, but that wouldn’t really be efficient.

Enter beanstalkd, a fast, distributed, in-memory workqueue service. You can push your data to beanstalkd and use another service to process them and ping the Mixpanel api server. This lets you take care of everything in the background in a really efficient way.

We’ve put together some packages that will help you in getting started. These contain all the dependencies for beanstalkd, as well as a processing script and client libraries for PHP and Python. To download a package, enter the following command in your shell:

PHP:

git clone git://github.com/mixpanel/mixpanel-php.git

Python:

git clone git://github.com/mixpanel/mixpanel-python.git

As you can see, these repos contain a fair number of packages.

Included projects (not made by Mixpanel)

Media_httpblogmixpanelcomwpcontentuploads200903picture41png_ykhsjsociwiouce

Once you’ve downloaded a package, you have everything you need to be up and running. Before you install the dependencies, take a quick look at what you’ve downloaded. The files you will be working with are:

logger.py or logger.php

  • This is the file you will be adding to your project.

mixpanel_service.py

  • Acts as the beanstalkd consumer; can be run as a daemon. You only need to run it.

beanstalkd (after installation)

  • This file is generated once you install beanstalkd. You can move it anywhere to install.

INSTALLATION INSTRUCTIONS:

To run an install script that takes care of everything:

sudo sh config.sh

Otherwise,

1. Install simplejson

cd simplejson-2.0.9
sudo python setup.py install

2. Install PyYAML

cd ../PyYAML-3.08

sudo python setup.py install

1. Install libevent

cd ../libevent-1.4.7-stable
sudo ./configure && make
sudo make install
sudo make verify

2. Install beanstalkd

cd ../beanstalkd-1.2
sudo ./configure && make

This will create a ‘beanstalkd’ file. To install, copy this file anywhere you
like.

3. Install pybeanstalk

cd ../pybeanstalk-0.11.1
sudo python setup.py install

Once these are installed, you can begin to integrate Mixpanel metrics into
your application.

Get the latest from Mixpanel
This field is required.