is node. js suitable for game background development?

Source: Internet
Author: User

How does the Web server and game server relate to each other?

Hundred Cattle Information Technology Bainiu.ltd organized and published in the blog Park

1. There are many kinds of games, let's look at MMORPG first.

No matter how simple the RPG server is unavoidable to deal with the situation of multi-person interaction, hundreds of people in the same scene, each client needs to receive other people's Operation information.

Second, the user's operation is very frequent, the general server tends to hold a long connection. And these links are frequently interactive, there is no obvious persistent partitioning strategy, so limit the server scale-out, the same scene often can only be placed on a physical machine to run.

Again, the end of the tour is usually not afraid to put the logic operation of the client, the user minutes to you to crack off, change the gold coins, brush two pieces of equipment again common. So this map server has to verify the operation of all the players in the map, and calculate a series of business logic such as monster AI and drop rate.

We can see that the traditional game server and the Web server have obvious differences, with long connection, multi-broadcast, complex business logic, zoning policy constraints and other unique business needs.

2. Let's take a look at what the benefits of concurrent bring to the game server are.

Concurrency is actually a procedural logic process, and he doesn't need multiple nuclear physics to support it. The idea is to make multiple independent logical flows look like they're running at the same time. Concurrency at the operating system level is a multi-process multithreaded model. Let the OS handle clock interruptions, i\o blocking, and so on.

For a server, if the task spends most of its time 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 the efficiency of the server and the response time.

For programmers, a separate logical flow means that you can accomplish your task in a reliable, simple, and loosely coupled context.

Because the OS handler logic switches back and forth into the kernel, some people feel that it is too slow to do some threads in user space, and control multiple logical streams within the process itself. Because of the limitations of the ability to describe language, it is too cumbersome to write on the C + + +. This resulted in Erlang, go, and Lua's coroutine syntax sugar.

node. JS is inherently self-controlling for multiple logical streams, but this logical flow is distributed according to the I\O state and priority. In the actual implementation, it uses non-blocking asynchronous i\o as much as possible, when a single task calls i\o, I stop it, wait for the i\o to complete the signal to send up, I restart it again.

Note that every time I run a task until it is done or the i\o call occurs, it does not actively switch to the other program stream. So if this task involves too much computation, then the entire map process will be blocked here.

And just because node. JS is asynchronous, you need to constantly write callbacks to listen to the i\o complete 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 the debugging development very big trouble.

3. Because of the above reasons, I do not recommend using node. JS in non-prototype MMORPG server development.

4. The recent rise of the Hand tour server is quite suitable for node. js, because the hand tour is limited to network problems , the server can only do critical data validation, there is no way to deal with the situation of special multi-person interaction. Server-side has been simplified with the Web server is no different, the business logic is simple, processing data processing, and then persistent.

is node. js suitable for game background development?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.