Ticket #3290: server.tac

File server.tac, 1.2 KB (added by exarkun, 6 years ago)

modified version of test.py which does more reporting

Line 
1from time import time
2from twisted.internet import protocol, reactor
3from twisted.application import service, internet
4
5class NotifyProtocol(protocol.Protocol):
6    def dataReceived(self, data):
7        now = time()
8        change = now - self.factory.lastTime
9        if change > self.factory.biggestDelay:
10            print 'New slowest:', change
11            self.factory.biggestDelay = change
12        self.factory.lastTime = now
13        self.factory.count += 1
14        if self.factory.count % 1000 == 0:
15            print "%s clients have connected." % self.factory.count
16        self.transport.write("HTTP/1.x 200 OK\r\n\r\n")
17
18
19class FirstNotifyProtocol(NotifyProtocol):
20    def connectionMade(self):
21        self.factory.lastTime = time()
22        self.factory.protocol = NotifyProtocol
23        NotifyProtocol.connectionMade(self)
24
25class NotifyFactory(protocol.ServerFactory):
26    protocol = FirstNotifyProtocol
27    def __init__(self):
28        self.count = 0
29        self.lastTime = time()
30        self.biggestDelay = 0
31
32application = service.Application('NotifyServer')
33internet.TCPServer(2000, NotifyFactory(), interface="0.0.0.0", backlog=50000).setServiceParent(service.IServiceCollection(application))