English 中文(简体)
Twisted Spread suitable for multiplayer racing sim?
原标题:

Do you think that Twisted Spread may be suitable (in terms of performance) for a multiplayer racing simulator? The rest of the application is based on Python-Ogre.

Can Perspective Broker run upon (reliable?) UDP?

最佳回答

It s almost certainly a reasonable protocol to start with. Remember the cardinal rule of optimization: don t do it. Working with any TCP-based protocol is going to be considerably easier than working with any UDP-based protocol. This is initially much more important to the success of your project than whether it takes 30 milliseconds or 45 milliseconds to send a message between your client and server. Eventually, when you ve gotten to the point where it s clear your project might actually succeed and you really need to make up those 15 (or however many) milliseconds, you can revisit the network layer and consider whether the performance bottleneck (be it latency or some other metric) is due to your choice of protocol. If so, that is the time to spend time evaluating various alternatives. It s only at that point that the effort of selecting the ideal protocol might pay off (since you re that much closer to a completed project) and by then you will have a significantly improved understanding of the problem and should have nailed down your requirements very specifically, two more things which will make the task of selecting the appropriate protocol (be it TCP- or UDP-based) that much easier and more likely to be correct.

问题回答

To your first question, yes, PB s performance can be perfectly adequate for a real-time game. Several games have been written using PB. For example, MV3D uses Twisted and Python-OGRE to present a shared physical simulation.

To your second question, PB runs upon a stream-oriented transport. It could run on top of "reliable UDP" using something like the PTCP module that comes along with vertex.

However, you should be aware that "reliable UDP" will generally perform much worse than plain old TCP. Routers all along the internet understand TCP and can optimize it by using that understanding. If you implement reliability on top of UDP, by necessity you will need to implement something functionally equivalent to TCP, and then several factors will penalize you:

  • your implementation of reliability has to run within your application, not in the operating system kernel.
  • your implementation of TCP has to do all the same stuff as TCP, otherwise you will face mysterious bugs in unanticipated network environments.
  • routers along the way can t optimize for your custom reliability layer

What can make UDP "faster" in some circumstances is discarding much of the work that TCP does, by being unreliable. If your messaging layer is unreliable, then you have to know that the data it s delivering can be arbitrarily discarded.

Usually, the data that s suitable for transmission over UDP within a game is movement data. When your position changes, you can send a UDP packet and it can be discarded because the game only cares about your most recent position - once an update has been received, all previous positions are irrelevant. So many games send movement data over one (unreliable) UDP channel, then all control messages over a more reliable TCP channel.

But, Jean-Paul s answer about optimization is a good indication of when you might want to consider implementing that optimization.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签