How are the Web servers and game servers connected?
1. The game is divided into many kinds, let's take a look at MMORPG first.
No matter how simple the RPG server is unavoidable to deal with the situation of multiple people interaction, hundreds of people in the same scene, each client needs to receive the other people's Operation information.
Second, the user's operation is very frequent, the general server tends to hold long connections. And these links are frequently interactive, there is no obvious persistent partitioning strategy, so limit the horizontal expansion of the server, the same scene often can only be placed on a physical machine to run.
Again, the end of the tour is usually afraid to put the logical operation of the client, the user minutes to you break, change the gold, brush two pieces of equipment is more common. So this map server has to verify the operation of all the players in the map, and calculate the monster AI, drop rate and a series of business logic.
We can see that the traditional game server and Web server have obvious differences, with long connection, multicast, complex business logic, zoning policy constraints and other unique business needs.
2. Let's take a look at what the benefits of concurrency bring to the game server.
Concurrency is actually a procedural logic process, and he doesn't need much nuclear physics to support it. The idea is to make multiple independent logical streams look like they're running at the same time. Concurrency at the operating system level is a multithreaded model of multiple processes. Let the OS handle clock interrupts, i\o blocking, and so on.
For servers, if most of the time spent on i\o, there is a concurrency mechanism to prevent the entire map service from being blocked by i\o access. When a task is blocked, allocate the spare computing resources to other tasks. In this case, concurrency is beneficial to server efficiency and response time.
For programmers, independent logical flows mean that they can accomplish their tasks in a reliable, simple, loosely coupled context.
Because the OS handler logic switches repeatedly into the kernel, some people feel too slow, do some of the user space in the thread, in-process control of multiple logical flows. Because of the limitation of language description ability, it is too troublesome to write on C/s + +. This creates the coroutine grammatical sugars in Erlang, go, and Lua.
Node.js inherently controls multiple logical flows, but this logical flow is distributed according to the I\O state and priority level. In the actual implementation, it as far as possible using non-blocking asynchronous I\o, a single task call i\o, I stopped it, and so i\o completed the signal sent up, I restart it.
Note that every time I run a task until it completes or a i\o call occurs, it does not actively switch to another program stream. So if this task involves too much computation, then the entire map process will be block here.
And because Node.js is asynchronous, it requires a constant write callback to listen to the i\o signal. The logical flow of a single task is interrupted multiple times. When the task becomes quite complex, that is, the so-called Callbak hell, will bring debugging development very big trouble.
3. Because of the above reasons, I do not recommend the use of node.js in the development of non prototyping MMORPG servers.
4. The recent rise of the hands of the server is quite suitable for node.js, because the hand tour this thing is limited to network problems , the server can only do critical data validation, and can not handle the situation of a special number of people interaction. The server side has been simplified to the Web server, the business logic is simple, processing data, and then persisted.