diff options
author | Prabhu Ramachandran | 2016-08-12 21:01:08 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-08-12 21:01:08 +0530 |
commit | b39eb538c08d4dd6761d6a970aadf58bde58a7ce (patch) | |
tree | 6732cb4c0f89ffc80b7b9aa60d54e2d3ff5c70f0 /yaksh/xmlrpc_clients.py | |
parent | 3738c8fefa8ac69508bb6daeee045c1f5ea0cb17 (diff) | |
download | online_test-b39eb538c08d4dd6761d6a970aadf58bde58a7ce.tar.gz online_test-b39eb538c08d4dd6761d6a970aadf58bde58a7ce.tar.bz2 online_test-b39eb538c08d4dd6761d6a970aadf58bde58a7ce.zip |
Use a tornado based server for the pool server.
With the previous XMLRPC based server, an XMLRPC server would respond to
a request for an available port. This does not work as the server can
only take about 2 simultaneous connections. The server pool now uses a
HTTP server via tornado which works extremely well. The django code
should not change at all as this is an internal change. This change
should make the code server far more robust and work for a very large
number of simultaneous users.
The http server also has a simple status page to indicate the current
load. This will not be correct on OSX due to limitations of the
multi-processing Queue implementation on OSX.
Diffstat (limited to 'yaksh/xmlrpc_clients.py')
-rw-r--r-- | yaksh/xmlrpc_clients.py | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/yaksh/xmlrpc_clients.py b/yaksh/xmlrpc_clients.py index 7124550..6bfe0d6 100644 --- a/yaksh/xmlrpc_clients.py +++ b/yaksh/xmlrpc_clients.py @@ -3,6 +3,7 @@ import time import random import socket import json +import urllib from settings import SERVER_PORTS, SERVER_POOL_PORT @@ -21,7 +22,7 @@ class CodeServerProxy(object): """ def __init__(self): pool_url = 'http://localhost:%d' % (SERVER_POOL_PORT) - self.pool_server = ServerProxy(pool_url) + self.pool_url = pool_url def run_code(self, language, test_case_type, json_data, user_dir): """Tests given code (`answer`) with the `test_code` supplied. If the @@ -34,7 +35,7 @@ class CodeServerProxy(object): ---------- json_data contains; user_answer : str - The user's answer for the question. + The user's answer for the question. test_code : str The test code to check the user code with. language : str @@ -57,21 +58,7 @@ class CodeServerProxy(object): return result def _get_server(self): - # Get a suitable server from our pool of servers. This may block. We - # try about 60 times, essentially waiting at most for about 30 seconds. - done, count = False, 60 - - while not done and count > 0: - try: - port = self.pool_server.get_server_port() - except socket.error: - # Wait a while try again. - time.sleep(random.random()) - count -= 1 - else: - done = True - if not done: - raise ConnectionError("Couldn't connect to a server!") + port = json.loads(urllib.urlopen(self.pool_url).read()) proxy = ServerProxy('http://localhost:%d' % port) return proxy |