• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

cerberus

threaded vs asynchronous

6 posts in this topic

Hi,

Well, I came upon the same questions some time ago. I dont have an absolute anwser, but..
I used new threads. But I also wrote a function that timesout the recv(), and I used the nonblocking mode (winsock2, the ioctl()). Personaly, I prefer this solution, lets your programe do more things at the same time, and you can also use threads to do easy pipline treatments.

But I have looked in some game codes with socketSpy, and QuakeWorld uses nonblocking mode sockets. They may be used for timeouts, but somehow, I think not. I think QW dosent use many threads, so, is my solution really the best... but it still is the one I would chose in most cases

DlooB

0

Share this post


Link to post
Share on other sites
Thats how we do it. A packet in queue feed by a blocking thread handling a single clients connection. Not sure how this scales up, as for each additonal client another thread has to be created. Thinking massive multiplayer, 1000s of threads wouldnt do at all, but our game isnt that type of game, so were not too concerned. You might want to consider it though. However i dont know how polling 1000s of sockets is any better.

-ddn

0

Share this post


Link to post
Share on other sites
Is this for a client application or a server application?

If it's for a server, the "message queue" or "round robin" approach is good. It provides fast response and doesn't require any complex threading or resource handling.

------------------
DavidRM
Samu Games

0

Share this post


Link to post
Share on other sites
The thread approach get my "thumbs up". Multiple sockets is a waste of resources + a security nightmare, and windows events are simply too slow.

For massive multiplayer you'd need a different approach altogether, similar to the way HTTP servers deal with massive amounts of clients - that is one thread per request, out of a given thread pool. When the pool size is exceeded, clients are put on hold...

/NJ

0

Share this post


Link to post
Share on other sites
Server side:

Asynchronous approach - I'm not a big fan of it. The code is pretty Windows-specific. Most socket samples you'll find on the net are blocking. Plus keeping track of all the async calls you've got going can be a headache. And its not that much of an improvement performance-wise- at some level, there is threading/async processing going on within the TCP/IP stack. In general, not worth it.

Message queue/round robin approach. This is good as long as each request can be served in a predictable manner. Ideally as fast as possible but you want predictablility over speed. Say you have two algorithms for handling requests - number one takes 200 ms on average but once in a while takes 2 seconds. Number two takes less than 500 ms every time. Even though on average number one is faster, number two is preferred because you have a gauranteed response time of 500 ms. If you get a request that takes a long time to serve it kills performance for everyone.

Thread-per-client approach. Best for when client requests are independent of each other, such as in web server. Can get complicated when requests require significant processing of shared state - the locking code can be complex,prone to deadlocks, and cause scalability chokepoints. The overhead of allocating threads can be dealt with by pre-allocating a pool of threads. Normally "unused" threads are kept suspended until they are grabbed from the pool and used as a client thread. When a client disconnects its servicing thread is returned to the pool.

Process-per-client - All of the above methods suffer from a flaw - if the request servicing code crashes, the whole server goes down and everyone has a bad day. Increased reliablility can be had at the cost of some overhead by having each request service routine in a separate process - if one crashes, it doesn't affect other clients. I know what you are thinking - I'm Mr. Bad-Ass Network Coder and my code never crashes. Well maybe so, but can you say that for the underlying OS? Or how about malicious attacks that exploit security holes in your protocol and bring down the server? Do you really want to have 1000 angry users when some script kiddie figures out an exploit or maybe just a few?

I'm sure the last two methods could be combined to give the efficiency of threading with the robustness of forking processes.

------------------
-vince

0

Share this post


Link to post
Share on other sites
Before I launch into the network code of this game I'm working on, I need to decide a few things. One thing I'm having trouble with is winsock and blocking/non-blocking stuff. I've written network code before that used WSAAsyncSelect()...it worked well enough but I didn't like relying on windows messaging to inform me when a network event happened. Would it make more sense to use blocking sockets in seperate threads? That way a recv() wouldn't hold up the whole program while it waited for data. Any thoughts? Thanks in advance!
0

Share this post


Link to post
Share on other sites
Glad to hear that I'm not the only one who thinks that mulitple processes can be a viable solution - In my last job I did a client/server solution that used forking processes, and had a terrible time convincing customers that it was NOT a problem - somebody must have convinced them that a server HAS to be threaded to scale ... Oh, the persistence of ignorance - SIGH!

/NJ

0

Share this post


Link to post
Share on other sites