<br><br><div class="gmail_quote">2008/4/13 Peter Cai &lt;<a href="mailto:newptcai@gmail.com">newptcai@gmail.com</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks a lot Andy for your explation.&nbsp; I am sorry for my poor English and I shall try to make it clearer this time.<br><br>1. UDP or TCP —— I could understood that implementing a strategy for retrying failures better than TCP is very unlikely.&nbsp; <br>

But I think maintaining about 3000 tcp connections at the same time might be quite hard too.&nbsp; <br>That&#39;s exactly why we use UDP in the last version written in C.<br>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.<br>

<br>Web server doesn&#39;t have this problem because they needn&#39;t keep every tcp connections.<br></blockquote><div><br>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.&nbsp; I would however consider adopting the strategy from web servers and not keeping tcp connections either.&nbsp; I&#39;d take their whole strategy and use http wherever possible even, twisted makes that easy.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">4.&nbsp; 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?&nbsp; <br>

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? <br></blockquote><div>With the two servers and backing up the mirror you wouldn&#39;t interrupt business.&nbsp; Similarly, it data shouldn&#39;t be particularly affected by backup operations. <br>
</div><div>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">5.&nbsp; Have you heard of BEA?&nbsp; Which was sold to Oracle in March.&nbsp;&nbsp; One of their main products is Java Application Server, WebLogic.&nbsp;&nbsp; I&#39;ve talked with their engineer when considerring using Java to write our server.&nbsp; He showed me some diagrams and told me that a sharp performance decrease was unavoidable when gc happened in any gc enabled system.&nbsp; (Of course he said Weblogic could do much better than any other systems ^_^)<br>

</blockquote><div>Maarten has spoken more directly to this point, but I cry foul anyway.&nbsp; Java GC *can* but shouldn&#39;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.<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">6.&nbsp; I want to know the difference between synchronised and asynchronised, block and unblocked APIs.&nbsp; I want to know the differences in fundamental level.<br>
I know that twisted uses &quot;epoll&quot;, but why it&#39;s more efficient?<br>
</blockquote><div>Everything has tradeoffs, and you probably can&#39;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.&nbsp; An async server lets your code explicitly yield control when it&#39;s going to be waiting for a I/O and resume again at a point and time when that I/O is complete.&nbsp; 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.&nbsp; I&#39;m sure someone else can explain further, for my own use I prefer it for a nice side effect.&nbsp; Async servers bypass the concept of threadsafe and synchronized sections since there can&#39;t be two live pieces of code in the whole server at any given time.&nbsp; Of course waiting for a synchronized section can be a performance issue too, but I mostly just don&#39;t like to write them.<br>
&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">8. Your advice sound very helpful!</blockquote><div>consulting rates available upon request :-) seriously, glad I could help, if you come to any interesting conclusions, won&#39;t you write them up in a blog somewhere? <br>
</div><div>&nbsp;<br>Andy Fundinger<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>2008/4/14 Andy Fundinger &lt;<a href="mailto:Andy@newworldelectric.com" target="_blank">Andy@newworldelectric.com</a>&gt;:&nbsp;</div>
</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div class="Wj3C7c">
I&#39;m not sure about books, but the questions seemed fun.&nbsp; I&#39;m curious how my answers measure up to the rest of the list here.<br><br><div class="gmail_quote"><div>2008/4/13 Peter Cai &lt;<a href="mailto:newptcai@gmail.com" target="_blank">newptcai@gmail.com</a>&gt;:<br>


</div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all!<br>
<br>
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&#39;s performance and how to do it correctly.<br><br>For example..<br><br>
1. UDP or TCP,which should I choose to gain higher performance?<br>
</blockquote></div><div>If you want the data to get there even if it&#39;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.&nbsp; 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.<br>


<br> </div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2. Should I catch data in memory instead of write it to db immediately?<br>


</blockquote></div><div>&nbsp;I wouldn&#39;t for local mysql databases.&nbsp; For a more distributed setup you might consider memcached.<br><br></div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


3. Could I make it run on cluster if cache data in memory ―― I think it might be quit hard to exchange data between instances of the server if I cache data in memory.<br>
</blockquote></div><div>that&#39;s exactly what memcached will take care of for you.<br></div><div><div>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


4. How to make hot backup?<br>
</blockquote></div><div>for maximum performance use a replicated pair of database servers and take the spare offline for backups.&nbsp; You could also bring the spare up only to capture the backup, though it will slow down the primary as it plays catchup.&nbsp;</div>

<div>
<div>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">5. Garbage collection might make the server halt for a moment<br>
</blockquote></div><div>I think this should be less than the latency of a publicly routed IP network, anyone have figures for gc and twisted?<br><br></div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


6. What is happening in a computer when an IP package received?<br>
</blockquote></div><div>What do you mean?&nbsp; What specifically do you need to know?<br><br></div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

7. Could I get some inspiration from how people write web server?<br>
</blockquote></div><div>this one I can suggest a book for, the twisted book <a href="http://www.oreilly.com/catalog/twistedadn/" target="_blank">http://www.oreilly.com/catalog/twistedadn/</a> , or if you&#39;re considering something other than twisted any reasonably thick python book will have an example web server.<br>


&nbsp;</div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">8. If i use an separate physical server to deploy the database, could I gain some performance improvement?&nbsp; Or the cost of communication between the db and the server could hurt the total performance?<br>




</blockquote></div><div>could go either way.&nbsp; With the effects of Python&#39;s GIL I&#39;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.&nbsp; At that point you need to develop a distributed application model and probably use multiple servers.&nbsp; If you hit that before you&#39;re running 200 users recheck your business model, if you hit it before 20 users recheck your architecture.&nbsp; <br>


&nbsp;</div></div>Andy Fundinger <br clear="all"><font color="#888888"><br>-- <br>Blog: <a href="http://channel3b.wordpress.com" target="_blank">http://channel3b.wordpress.com</a><br>Second Life Name: Ciemaar Flintoff<br><br>

I am a sig Virus. Please put me in your sig so that I can continue to replicate.
</font><br></div></div><div class="Ih2E3d">_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></div></blockquote></div><font color="#888888"><br><br clear="all"><br>-- <br>当只有一张纸和一支笔的时候, 我相信你写下的东西对你来说就是真实的, 不管他们到底是不是真的。
</font><br>_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Blog: <a href="http://channel3b.wordpress.com">http://channel3b.wordpress.com</a><br>Second Life Name: Ciemaar Flintoff<br><br>I am a sig Virus. Please put me in your sig so that I can continue to replicate.