Skip to content

ganesh-k13/titanium-silver

Repository files navigation

Titanium-Silver

Build Status stability-wip licensebuttons by-sa

Description

Titanium-Silver is a python package for automating lab evalution using dockers.

  • Built an online judge for source code evaluation where user submits source code and receives results such as execution time, memory usage and number of passed testcases.
  • Each user program is run in a docker container with limited memory and processing power. The number of active containers are configurable to guarantee no server crashes. Each container is spawned on a different thread to improve efficiency.
  • The server is developed using Flask and deployed using Gunicorn. Nginx is used as reverse proxy. Nginx takes care of load balancing.
  • Tests are written using pytest and continuous integration using Travis.
  • Results:
    • 50 simultaneous requests: 27.18 seconds
    • 100 simultaneous requests: 50.18 seconds
    • 10 requests with 5 seconds interval, 5 times (Realistic scenario designed and tuned for): 27.64 seconds
    • Above result translates to 0.55 seconds per request with average waiting time for requests being 0.528 seconds.

Installation

This package requires:

Please verify docker's installation:

$ sudo docker run hello-world

Install Required Packages:

$ sudo pip3 install -r requirements.txt

Install Titanium-Silver:

$ sudo pip3 install -e . # PWD must be main folder with setup.py

Development:

Steps:

  1. Install nvm to install node and npm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
source ~/.bashrc
nvm install node
cd <project_root>/frontend
npm install
<in one shell> $ npm run start
<in another shell> $ ./run.sh

Production:

Steps:

  1. Do these:
$ cd frontend/ && npm run build
$ cd server/flaskr/ 
$ ln -s ../../frontend/build/static static
$ ln -s ../../frontend/build/ templates
  1. Open the file index.html in frontend/build. For each <script> tag, add this: type="text/babel"
  2. Remove the <link> for manifest.json
  3. For favicon.ico to load do this:
    1. Move favicon.ico to build/static.
    2. Change href of <link> to : {{url_for("static",filename="./favicon.ico")}}

Tests

$ pytest # Very Intensive, Less verbose
$ # Recommended:
$ sudo pytest tests/test_basic.py
$ sudo pytest tests/test_basic_100.py
$ sudo pytest tests/test_basic_50.py
$ sudo pytest tests/test_server_simulation.py

Usage

Docker module usage:

usage: script.py [-h] [-n [NUM]] [-s [SLEEP]]

optional arguments:
  -h, --help  show this help message and exit
  -n [NUM]    Number of containers=(0,50]
  -s [SLEEP]  Sleep duration of client file

# or as package:

>>> from titanium_silver.docker_client import Docker_Client
>>> dcli = Docker_Client()
>>> t = dcli.spawn_process(name='prototype%d'%i, num=i, sleep=5000, path=os.getcwd()+'/tests/SC') # returns a thread with container
>>> t.result_queue.get().decode('utf-8') # Get result

License: Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)

Authors: