Setting up a Sage server

by Jason Grout

I recently set up a Sage server, and here are very rough notes of what I did.

Hardware Requirements

RAM

The biggest bottleneck seems to be RAM; that will determine how many simultaneous users you can have. From some informal tests, it seems that the Sage notebook uses about 150MB of RAM for the server and about 50MB for a worksheet instance. If the OS uses between 512 and 1G of RAM, then I conservatively calculate that the following amounts of RAM will support the corresponding numbers of users (if the users are doing just basic calculations and not using a lot of RAM):

RAM (GB)

Simultaneous worksheets

1

5

2

20

3

40

4

60

8

140

12

200

These numbers have not been tested. If anyone has real-world numbers, please correct the table above.

Note that the numbers above are for simultaneously running worksheets. There can be many, many more accounts on the server.

Install the server

I started with a fresh copy of Ubuntu 9.10, with a working Sage compiled from source (which means I had to install some extra packages so that Sage compiles and runs; see the Sage README).

sudo apt-get install apache2

sudo a2enmod proxy
sudo a2enmod proxy_http

<VirtualHost *:80>   
ServerName YOUR_SERVER_NAME

ProxyRequests Off
ProxyPreserveHost On

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/

 DocumentRoot /
 <Location />   DefaultType text/html
 </Location>

   ErrorLog /var/log/apache2/error.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn

   CustomLog /var/log/apache2/access.log combined
   ServerAdmin YOUR_SERVER_ADMIN_EMAIL_ADDRESS
 </VirtualHost>

sudo a2dissite default
sudo a2ensite sagenotebook
sudo /etc/init.d/apache2 restart

sudo addgroup sageuser
sudo adduser --disabled-password sageserver
for i in $(seq 0 9); do
 sudo adduser --disabled-password --ingroup sageuser sage$i
done

account  required     pam_access.so nodefgroup

-:(sageuser):ALL EXCEPT localhost
-:sageserver:ALL

sudo -u sageserver -i "ssh-keygen -t dsa"
for i in $(seq 0 9); do
 sudo cat ~sageserver/.ssh/id_dsa.pub | sudo -u sage$i -i "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys "
done

sudo -u sageserver -i "ssh sage0@localhost echo Done"

echo "notebook(interface='localhost', port=8000, accounts=True, timeout=1200, server_pool=['sage%d@localhost'%i for i in range(10)], ulimit='-u 100 -t 3600 -v 500000', open_viewer=False)" | ~/sage/sage

sudo -u sageserver -i "~/sage/sage -i jsmath_image_fonts-1.4.p3"

To start the sage server, do the following. Note that since I am using sudo to run commands as sageserver, instead of logging in as sageserver, I have to do the script /dev/null trick to get screen to work.

sudo su -l sageserver
script /dev/null
screen
./startnotebook

I also added this to ~/sage/sage to control process limits:

if [[ `whoami` = sage* ]]; then
   echo "User " `whoami`
   ulimit -v 1500000 -u 300 -n 128 -t 1800
fi

Additional Notes