-
Notifications
You must be signed in to change notification settings - Fork 6
Example: Remote Code Runner
Kanak Biscuitwala edited this page Dec 11, 2013
·
2 revisions
This example demonstrates a Helix system that contains Python participants and a Python spectator. Through a web frontend, we can submit Python programs that will run on machines that register as "code runners." There are many applications for this in real systems:
- We want to make sure the program runs the same in different environments
- We want to distribute the load of programs coming in that need to be run
- We want to run the same code on a set of machines to change some state on those machines
- We want to run code, but the machine we have direct access to is underpowered
- many others
The code here is a bare-bones example of how this might be implemented. It's not recommended that this run publicly in production as it is capable of running arbitrary code, which could lead to disastrous situations.
-
coderunner.py
-- the coderunner frontend -
coderunner_cluster.yaml
-- YAML file describing the cluster structure -
coderunner_node.yaml
-- process that can run code -
index.tpl
-- home page template of the frontend -
runnermodel.py
-- the Helix state model of a coderunner
sudo easy_install bottle
sudo easy_install pyhelix
wget http://www.us.apache.org/dist/incubator/helix/0.6.2-incubating/binaries/helix-core-0.6.2-incubating-pkg.tar
tar xf helix-core-0.6.2-incubating-pkg.tar
cd helix-core-0.6.2-incubating/bin
This is a basic setup to get some code runners and a frontend running on a local machine. To make this distributed, just run the processes on different machines with different hosts and ports.
./start-standalone-zookeeper.sh
./yaml-cluster-setup.sh localhost:2199 /path/to/pyhelix/examples/coderunner_cluster.yaml
./run-helix-controller --zkSvr localhost:2199 --cluster coderunner-cluster
# Run each of these in the background or in separate shells
python coderunner_node.py --host localhost --port 8001 --zkSvr localhost:2199
python coderunner_node.py --host localhost --port 8002 --zkSvr localhost:2199
python coderunner_node.py --host localhost --port 8003 --zkSvr localhost:2199
python coderunner.py --host localhost --port 8000 --zkSvr localhost:2199
- Browse to
http://localhost:8000
- Run some Python programs