.BANCHO. Switched to tornado+gevent

This commit is contained in:
Nyo 2016-08-23 20:16:47 +02:00
parent 0e74e5c1ce
commit 095f9b3bc9
6 changed files with 11 additions and 19 deletions

View File

@ -10,13 +10,14 @@ This is Ripple's bancho server. It handles:
## Requirements ## Requirements
- Python 3.5 - Python 3.5
- MySQLdb (`mysqlclient` or `mysql-python`) - MySQLdb (`mysqlclient` or `mysql-python`)
- Tornado (`tornado`) - Tornado
- Bcrypt (`bcrypt`) - Gevent
- Bcrypt
## How to set up pep.py ## How to set up pep.py
First of all, install all the dependencies First of all, install all the dependencies
``` ```
$ pip install mysqlclient tornado bcrypt $ pip install mysqlclient tornado gevent bcrypt
``` ```
then, run pep.py once to create the default config file and edit it then, run pep.py once to create the default config file and edit it
``` ```

View File

@ -586,7 +586,6 @@ def tillerinoLast(fro, chan, message):
stars = oppaiData["stars"] stars = oppaiData["stars"]
msg += " | {0:.2f} stars".format(stars) msg += " | {0:.2f} stars".format(stars)
return msg return msg
except Exception as a: except Exception as a:
log.error(a) log.error(a)

View File

@ -49,7 +49,6 @@ class config:
self.config.get("db","workers") self.config.get("db","workers")
self.config.get("server","port") self.config.get("server","port")
self.config.get("server","threads")
self.config.get("server","gzip") self.config.get("server","gzip")
self.config.get("server","gziplevel") self.config.get("server","gziplevel")
self.config.get("server","cikey") self.config.get("server","cikey")
@ -94,7 +93,6 @@ class config:
self.config.add_section("server") self.config.add_section("server")
self.config.set("server", "port", "5001") self.config.set("server", "port", "5001")
self.config.set("server", "threads", "16")
self.config.set("server", "gzip", "1") self.config.set("server", "gzip", "1")
self.config.set("server", "gziplevel", "6") self.config.set("server", "gziplevel", "6")
self.config.set("server", "cikey", "changeme") self.config.set("server", "cikey", "changeme")

View File

@ -5,6 +5,7 @@ from tornado.ioloop import IOLoop
from objects import glob from objects import glob
from raven.contrib.tornado import SentryMixin from raven.contrib.tornado import SentryMixin
from raven.contrib.tornado import AsyncSentryClient from raven.contrib.tornado import AsyncSentryClient
import gevent
class asyncRequestHandler(tornado.web.RequestHandler): class asyncRequestHandler(tornado.web.RequestHandler):
""" """
@ -58,8 +59,10 @@ def runBackground(data, callback):
func, args, kwargs = data func, args, kwargs = data
def _callback(result): def _callback(result):
IOLoop.instance().add_callback(lambda: callback(result)) IOLoop.instance().add_callback(lambda: callback(result))
glob.pool.apply_async(func, args, kwargs, _callback) #glob.pool.apply_async(func, args, kwargs, _callback)
g = gevent.Greenlet(func, *args, **kwargs)
g.link(_callback)
g.start()
def checkArguments(arguments, requiredArguments): def checkArguments(arguments, requiredArguments):
""" """

View File

@ -20,7 +20,6 @@ tokens = tokenList.tokenList()
channels = channelList.channelList() channels = channelList.channelList()
matches = matchList.matchList() matches = matchList.matchList()
restarting = False restarting = False
pool = None
fLocks = fileLocks.fileLocks() fLocks = fileLocks.fileLocks()
verifiedCache = {} verifiedCache = {}
cloudflare = False cloudflare = False

12
pep.py
View File

@ -1,7 +1,6 @@
"""Hello, pep.py here, ex-owner of ripple and prime minister of Ripwot.""" """Hello, pep.py here, ex-owner of ripple and prime minister of Ripwot."""
import sys import sys
import os import os
from multiprocessing.pool import ThreadPool
import threading import threading
# Tornado # Tornado
@ -9,6 +8,8 @@ import tornado.ioloop
import tornado.web import tornado.web
import tornado.httpserver import tornado.httpserver
import tornado.gen import tornado.gen
from gevent import monkey as brit_monkey
brit_monkey.patch_all()
# Raven # Raven
from raven.contrib.tornado import AsyncSentryClient from raven.contrib.tornado import AsyncSentryClient
@ -98,15 +99,6 @@ if __name__ == "__main__":
glob.tokens.deleteBanchoSessions() glob.tokens.deleteBanchoSessions()
consoleHelper.printDone() consoleHelper.printDone()
# Create threads pool
try:
consoleHelper.printNoNl("> Creating threads pool... ")
glob.pool = ThreadPool(int(glob.conf.config["server"]["threads"]))
consoleHelper.printDone()
except:
consoleHelper.printError()
consoleHelper.printColored("[!] Error while creating threads pool. Please check your config.ini and run the server again", bcolors.RED)
try: try:
consoleHelper.printNoNl("> Loading chat filters... ") consoleHelper.printNoNl("> Loading chat filters... ")
glob.chatFilters = chatFilters.chatFilters() glob.chatFilters = chatFilters.chatFilters()