Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

C# and IOCP on an MMORPG server.

This topic is 5238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m just wondering about the reliability of an IOCP server written in C#. If anyone has any form of comparison between a well written C++ IOCP server program and a similar C# IOCP server program I would appreciate it. Basically what I am looking for is something like the processing time it takes for similar jobs to complete on each server under different levels of traffic. If you can avoid book references it would be helpfull since the closest bookstore to me with any decent programming titles is 90 miles away :-/ If you''re wondering why I''m considering C# over C++ it is because of the improved I/O performance that C# offers and the increased security that is so important in a Client/Server environment. That along with the decreased development time when working with C# make it a fairly viable option when you consider the fact that emergency server patches will take half the time to deploy. Anyway, thanks in advance for the help, -Dave Mandrella PS: Please don''t generalize (eg: The C++ one will be faster.) I am already expecting a performance hit on the C# version, I''d just like to know how much of a hit to expect over the typical 3% - 5% performance downgrade C# experiences.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I am having a hard time finding a sample of a well written C++ IOCP server program at all... Where are you finding information on this at all without books? It seems when it comes to IOCP, programmers like to keep their tricks hidden...

Share this post


Link to post
Share on other sites
The information is out there if you look hard enough.

Here are some C# articles that discuss IOCP (And do a very good job at it):

http://www.devarticles.com/c/a/C-Sharp/IOCP-Thread-Pooling-in-C-sharp-Part-I/

http://www.devarticles.com/c/a/C-Sharp/IOCP-Thread-Pooling-in-C-sharp-Part-II/

And here's one that discuss C++ IOCP using Winsock 2.0:

http://msdn.microsoft.com/msdnmag/issues/1000/winsock/

You're halfway right about programmers trying to keep IOCP techniques a secret. The reason you don't really see much (if any) IOCP code out there on the net is because of the variance that each project will have between implementations. There are general overviews that can point you in the right direction, but barely ever will you find an actual full-functioned example because it won't be all that usefull for 95% of the people that look at it.

That said, the articles above are a very good start...especially the C# article.

-Dave Mandrella

EDIT: This isn't an answer to my original post

[edited by - thedavil on January 18, 2004 6:13:09 AM]

Share this post


Link to post
Share on other sites
> If anyone has any form of comparison between a well written
> C++ IOCP server program and a similar C# IOCP server program
> I would appreciate it.

I never used C# for this kind of programming, but I can give you hints where things are likely to break down based on my experience with IOCP/C++.

The WSAOVERLAPPED-derive structure you pass around for posting recv or send requests is being passed down the kernel which is going to lock it in RAM to make sure it is available when the event is triggered. If you post too many send requests, your RAM will fill quickly to the point where the remaining of the system will start swapping madly. You can avoid this by using a semaphore. In C++, you can control where memory is allocated by providing a secondary heap for the WSAOVERLAPPED object and make sure whatever you allocate falls on 4K boundaries or at least is packed thight enough to minimize the number of locked RAM pages. Now, C# handles its own memory pool and we simply can''t peek & poke into it as we see fit. In C++, you can always recycle spent WSAOVERLAPPED struct by putting them in a free list and pull one out when you need it; C# doesn''t allow you to work this way as it has its own object management system.

It is possible to avoid the locking by specifying a large enough buffer { setsockopt( ... SOL_SOCKET, SO_SNDBUF,...) } for sending; but by doing so, you incur memory copying each and every time you transfer something which is not a good idea. On the receiving end this is not a problem as each worker thread is associated a pre-allocated WSAOVERLAPPED struct and it''s a matter of adjusting the number of worker threads.

In essence, C#''s memory paradigm is likely to be the top culprit in the performance drain of your application. How much? I can''t tell and the best way would be to code both a C++ and a C# version and perform benchmarks.

All in all, I suggest you package an IOCP/C++ server into a neat little COM object you can then use under managed C++ and then under C#''s environment. This way, memory management issues are localized to the IOCP server code only.

Hope this helps.

-cb

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!