开发者

What to use for high-performance server coding? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I need to build a server to accept client connection with a very high frequency and load (each user will send a request each 0.5 seconds and should get a response in under 800ms, I should be able to support thousands of users on one server). The assumption is that the SQL Server is finely tuned and will not pose a problem. (assumption that of course might not be true)

I'm looking to write a non-blocking server to accomplish this. My back end is an SQL Server which is sitting on another machine. It doesn't have to be updated live - so I think I can cache most of the data in memory and dump it to the DB every 10-20 seconds.

Should I write the server using C# (which is more compatible with SQL Server)? maybe Python with Tornado? What should be my considerations when write a high-performance server?

EDIT: (added more info)

  1. The Application is a game server.
  2. I don't really know the actual traffic - but this is the prognosis and the server should support it and scale well.
  3. It's hosted "in the cloud" in a Dat开发者_如何学运维acenter.
  4. Language doesn't really matter. Performance does. (a Web service can be exposed on the SQL Server to allow other languages than .NET)
  5. The connections are very frequent but small (very little data is returned and little computations are necessary).
  6. It should hold most of the data in the memory for fastest performance.

Any thoughts will be much appreciated :)

Thanks


Okay, if you REALLY need high performance, don't go for C#, but C/C++, it's obvious.

In any case, the fastest way to do server programming (as far as I know) is to use IOCP (I/O Completion Ports). Well, that's what I used when I made a MMORPG server emulator, and it performed faster than the official C++ select-based servers.

Here's a very complete introduction to IOCP in C# http://www.codeproject.com/KB/IP/socketasynceventargs.aspx

Good luck !


Use the programming language that you know the most. It's a lot more expensive to hunt down performance issues in an large application that you do not fully understand.

It's a lot cheaper to buy more hardware.


People will say C++, because garbage collection in .Net could kill your latency. You could avoid garbage collection though if you were clever, by reusing existing managed objects.

Edit: your assumption about SQL Server is probably wrong. You need to store your state in memory for random access. If you need to persist changes, journal them to the filsystem and consolidate them with the database infrequently

Edit 2: You will have a lot different threads talking to the same data. In order to avoid blocking and deadlocks, learn about lock-free programming (Interlocked.CompareExchange etc)


I was part of a project that included very high-performance server code, which actually included the ability to response with a TCP packet within 12 milliseconds or so.

We used C# and I must agree with jgauffin - a language that you know is much more important than just about anything.

Two tips:

  1. Writing to console (especially in color) can really slow things down.

  2. If it's important for the server to be fast at the first requests, you might want to use a pre-JIT compiler to avoid JIT compilation during the first requests. See Ngen.exe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜