class ServerSSL(object):
...
Don't write your own context factory. Use twisted.internet.ssl.CertificateOptions
instead. It has fewer problems than what you have here.
def __del__(self):
self.session.close()
First rule of __del__
: don't use __del__
. Adding this method doesn't give you automatic session cleanup. Instead, it almost certainly guarantees your session will never be be cleaned up. Protocols have a method that gets called when they're done - it's called connectionLost
. Use that instead.
result = session.execute(sqlalchemy.select([Users]).where(Users.name == data['user']))
result = result.fetchone()
Twisted is a single-threaded multi-tasking system. These statements block on network I/O and database operations. While they're running your server isn't doing anything else.
Use twisted.enterprise.adbapi
or twext.enterprise.adbapi2
or alchimiato perform database interactions asynchronously instead.
class ServerClientSSL(LineReceiver):
...
There are lots of protocols better than LineReceiver
. The simplest improvement you can make is to switch to Int32StringReceiver
. A more substantial improvement would be to switch to twisted.protocols.amp
.
1) How i can decrease time for serialization at JSON?
Use a faster JSON library. After you fix the blocking database code in your application, though, I doubt you'll still need a faster JSON library.
2) Maybe something exists for better than LineReciver, for creating communication between server and client? Or i can increase length of received lines?
LineReceiver.MAX_LENGTH
. After you switch to Int32StringReceiver
or AMP
you won't need this anymore though.