I'll 400 clients in the first deploy and some thousands later. Do you think are many?
2009/4/28, Lucas Taylor <[email protected]>: > On 4/28/09 4:11 AM, Juanjo Conti wrote: >> >> Another question. Thinking twisted (and thinking about performance), >> it's ok to loop every 30 seconds over the clients asking their status or >> should be better to schudle a new polling rutine starting 30 seconds >> from now every time a client is connected? In the second approach the >> polls will be more spread? Is a good Idea? > > > If this basic approach works for your application, then either way seems > simple enough to swap out and test. Whether it is a good idea or not > depends on your application, the # of clients, etc. > > I don't think you're going to find it makes much of a difference for > some low number of connected clients, so keeping a single timer in the > factory seems easier to manage. > > But if you need more control and want to make sure your clients aren't > being polled before it is necessary (i.e. < 30s from connect), then your > second approach might be better. > > Lucas > >> It will be something like: >> >> from twisted.internet import reactor, task >> >> class StatusPollingReceiver(LineOnlyReceiver): >> def requestStatus(self): >> self.transport.write('stat\r\n') >> >> def connectionMade(self): >> self.factory.clients.append(self) >> statusloop = task.LoopingCall(self.requestStatus) >> statusloop.start(30.0) >> >> def lineReceived(self, line): >> print('Rx: %s' % line) >> >> def connectionLost(self, reason): >> self.factory.clients.remove(self) >> >> >> class StatusPollingFactory(Factory): >> >> def __init__(self): >> self.clients = [] >> >> def stopFactory(self): >> self.statusloop.stop() >> >> def buildProtocol(self, addr): >> p = StatusPollingReceiver() >> p.factory = self >> return p > > _______________________________________________ > Twisted-Python mailing list > [email protected] > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > -- Juanjo Conti _______________________________________________ Twisted-Python mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
