[Twisted-Python] Performance issues of twisted.

Andy Fundinger Andy at NewWorldElectric.com
Sun Apr 13 22:10:52 MDT 2008


2008/4/13 Peter Cai <newptcai at gmail.com>:

> Thanks a lot Andy for your explation.  I am sorry for my poor English and
> I shall try to make it clearer this time.
>
> 1. UDP or TCP ¡ª¡ª I could understood that implementing a strategy for
> retrying failures better than TCP is very unlikely.
> But I think maintaining about 3000 tcp connections at the same time might
> be quite hard too.
> That's exactly why we use UDP in the last version written in C.
> We have to write a lot of codes to handle retranmission and we have to
> send KEEP Alive Message to make sure that if the client program is still
> working.
>
> Web server doesn't have this problem because they needn't keep every tcp
> connections.
>

well, at a glance 3000 TCP connections should be similarly resource
intensive than 3000 simulated connection over UDP, but you have a working
app to compare with.  I would however consider adopting the strategy from
web servers and not keeping tcp connections either.  I'd take their whole
strategy and use http wherever possible even, twisted makes that easy.

4.  But if we choose TCP or we cache any data in memory, the bussiness shall
> be cut off for a short moment and all clients have to relogin?
> All data cached in memory shall be lost any the client might feel like
> that they lost some time in the game. Is that true?
>
With the two servers and backing up the mirror you wouldn't interrupt
business.  Similarly, it data shouldn't be particularly affected by backup
operations.


> 5.  Have you heard of BEA?  Which was sold to Oracle in March.   One of
> their main products is Java Application Server, WebLogic.   I've talked with
> their engineer when considerring using Java to write our server.  He showed
> me some diagrams and told me that a sharp performance decrease was
> unavoidable when gc happened in any gc enabled system.  (Of course he said
> Weblogic could do much better than any other systems ^_^)
>
Maarten has spoken more directly to this point, but I cry foul anyway.  Java
GC *can* but shouldn't be run manually, and you can use multiple processes
or servers to ensure that though a process is slowed down the system as a
whole is unaffected.


> 6.  I want to know the difference between synchronised and asynchronised,
> block and unblocked APIs.  I want to know the differences in fundamental
> level.
> I know that twisted uses "epoll", but why it's more efficient?
>
Everything has tradeoffs, and you probably can't get a real answer without
describing your use case in rather more detail, but part of it is about
control and being able to make certain optimizations.  An async server lets
your code explicitly yield control when it's going to be waiting for a I/O
and resume again at a point and time when that I/O is complete.  A threaded
server runs threads in parallel hoping that some of them will not be blocked
and thus the server will be able to cut through the total workload.  I'm
sure someone else can explain further, for my own use I prefer it for a nice
side effect.  Async servers bypass the concept of threadsafe and
synchronized sections since there can't be two live pieces of code in the
whole server at any given time.  Of course waiting for a synchronized
section can be a performance issue too, but I mostly just don't like to
write them.


> 8. Your advice sound very helpful!

consulting rates available upon request :-) seriously, glad I could help, if
you come to any interesting conclusions, won't you write them up in a blog
somewhere?

Andy Fundinger

2008/4/14 Andy Fundinger <Andy at newworldelectric.com>:
>
I'm not sure about books, but the questions seemed fun.  I'm curious how my
> > answers measure up to the rest of the list here.
> >
> > 2008/4/13 Peter Cai <newptcai at gmail.com>:
> >
> > > Hi all!
> > >
> > > I am preparing to write a server application (you may think of it as
> > > an online game server) with twisted, but I am worrying about it's
> > > performance and how to do it correctly.
> > >
> > > For example..
> > >
> > > 1. UDP or TCP£¬which should I choose to gain higher performance?
> > >
> > If you want the data to get there even if it's late use TCP, if late
> > data is not useful to you or needs to be handled some special way use UDP
> > which will simply lose packets if they happen to not go through.  It is
> > possible but rather unlikely that you can implement a strategy for retrying
> > failures better than TCP unless you relax the constraint of eventually
> > getting the data through.
> >
> > 2. Should I catch data in memory instead of write it to db immediately?
> > >
> >  I wouldn't for local mysql databases.  For a more distributed setup you
> > might consider memcached.
> >
> > 3. Could I make it run on cluster if cache data in memory ¨D¨D I think it
> > > might be quit hard to exchange data between instances of the server if I
> > > cache data in memory.
> > >
> > that's exactly what memcached will take care of for you.
> >
> >
> > > 4. How to make hot backup?
> > >
> > for maximum performance use a replicated pair of database servers and
> > take the spare offline for backups.  You could also bring the spare up only
> > to capture the backup, though it will slow down the primary as it plays
> > catchup.
> >
> >
> > > 5. Garbage collection might make the server halt for a moment
> > >
> > I think this should be less than the latency of a publicly routed IP
> > network, anyone have figures for gc and twisted?
> >
> > 6. What is happening in a computer when an IP package received?
> > >
> > What do you mean?  What specifically do you need to know?
> >
> > 7. Could I get some inspiration from how people write web server?
> > >
> > this one I can suggest a book for, the twisted book
> > http://www.oreilly.com/catalog/twistedadn/ , or if you're considering
> > something other than twisted any reasonably thick python book will have an
> > example web server.
> >
> >
> > > 8. If i use an separate physical server to deploy the database, could
> > > I gain some performance improvement?  Or the cost of communication between
> > > the db and the server could hurt the total performance?
> > >
> > could go either way.  With the effects of Python's GIL I'd expect a
> > multi-core server with database and game server on one box would be fine
> > until you hit a scaling limit and your server is eating a whole core.  At
> > that point you need to develop a distributed application model and probably
> > use multiple servers.  If you hit that before you're running 200 users
> > recheck your business model, if you hit it before 20 users recheck your
> > architecture.
> >
> > Andy Fundinger
> >
> > --
> > Blog: http://channel3b.wordpress.com
> > Second Life Name: Ciemaar Flintoff
> >
> > I am a sig Virus. Please put me in your sig so that I can continue to
> > replicate.
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> >
> >
>
>
> --
> µ±Ö»ÓÐÒ»ÕÅÖ½ºÍÒ»Ö§±ÊµÄʱºò, ÎÒÏàÐÅÄãдϵĶ«Î÷¶ÔÄãÀ´Ëµ¾ÍÊÇÕæʵµÄ, ²»¹ÜËûÃǵ½µ×ÊDz»ÊÇÕæµÄ¡£
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>


-- 
Blog: http://channel3b.wordpress.com
Second Life Name: Ciemaar Flintoff

I am a sig Virus. Please put me in your sig so that I can continue to
replicate.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20080414/25d7b8d4/attachment.html>


More information about the Twisted-Python mailing list