Jump to content

Little Curious how Multiplayer Works


Monkuar
Go to solution Solved by kicken,

Recommended Posts

I'm curious how a client or game connects to mysql and updates it.

 

In Path of Exile, u have a item that lets you change the amount of sockets a item has.

 

For instance, everytime when a user uses the item (They could have over 2000) on the item.... is it in essence 1 MYSQL UPDATE EACH time? (1 query)? Or how exactly does it register through the server or sustain lower optimization or performance?

 

i know this sounds dumb, but I've always wondered this stuff.  If that is true, wouldn't those queries and all the active users just rape the servers?  

 

I've looked into socket.io / etc is that kind of like the same thing as Winsocket? (Wouldn't this be even MORE server intensive with an active connection?) 

 

Just curious, I know you guys think I am clueless and have no idea what im talking about, but please...

 

Also, im curious on why people say socket.io is better? If you have a chat system using socket.io and 5 active users.  It's constantly refreshing and querying from the chat table to display all the data right? Wouldn't a simple ajax poll every 2-3 seconds would be fine? O_o  I know this wouldn't really work for MMO's because it would be laggy data, but then in essence is that socket.io grabbing all the data from the chat table (querying it) every second? Wouldn't that just destroy the server @_@

Edited by Monkuar
Link to comment
Share on other sites

For instance, everytime when a user uses the item (They could have over 2000) on the item.... is it in essence 1 MYSQL UPDATE EACH time? (1 query)? Or how exactly does it register through the server or sustain lower optimization or performance?

I would imagine (but have no pratical experience/knowledge) that a game server most likely handles a lot of the operations/changes that need done in-memory and has some kind of background thread which will periodically save changes to the database. That way it would be able to service all the clients quickly without waiting on the database.

 

Also, im curious on why people say socket.io is better? If you have a chat system using socket.io and 5 active users.  It's constantly refreshing and querying from the chat table to display all the data right?

No, socket.io is just a wrapper for various ways of establishing "real-time" two-way communication. Exactly what it does depends on what the browser/server supports. A modern browser with Websocket support would just keep one persistent socket open to send data through. A browser Flash support uses some small flash program to emulate websockets. A browser with XHR will use either long or short polling, depending on what your server supports.

 

This ability for socket.io to adapt to what is available is why it is popular. It will use the most efficient method it can while keeping a constant api for your application to use.

 

Wouldn't a simple ajax poll every 2-3 seconds would be fine?

Sure, you'd just have a lot of unnecessary requests constantly checking on things. If it is the only method available though, then that is what you do.

Link to comment
Share on other sites

A modern browser with Websocket support would just keep one persistent socket open to send data through.

 

When you say a persisten socket, does this mean the chat table is being queried like every second in essense?( For a chat room for example) or only when new data is available? Even if it does do it when new data is available a simple 10-20room chat room with all active users using socket.io wouldn't that just rape the server? How does MMO's do it with World/Trade chat? Thousands of active users just querying that table/refreshing it across all people, seems a bit overlord?

 

 

Kicken

I would imagine (but have no pratical experience/knowledge) that a game server most likely handles a lot of the operations/changes that need done in-memory and has some kind of background thread which will periodically save changes to the database. That way it would be able to service all the clients quickly without waiting on the database.

 

Would this be why sometimes if u DC you lose data on ur character because it wasn't saved to Server? (Wouldn't this need to be updated like every second as well) for no data loss? How do these servers perform so good under these load, I dont get it :/

 

I'm am making a web based RPG, I got inventory system done with jquery/drag/drop/monster battle AI/loot functions to give loot based on char level/etc (when monster died) /etc/etc, but if I do PVP it will obviously be turned based, but not sure if I want to do comet/longpolling/simple 1-2sec ajax/socket.io....

 

I also looked into the server files for a Diablo 2 Private Server, they store all character data into a .d2cs file or something on the server, then that file get's written everytime a person finds a item or whatnot, (get's read and written from the client) which we don't got source code for, only David Brevik does.

 

Also, does every windows programmed MMO/Multiplayer  game have to use Winsock?

Edited by Monkuar
Link to comment
Share on other sites

  • Solution

When you say a persisten socket, does this mean the chat table is being queried like every second in essense?( For a chat room for example) or only when new data is available?

By a persistent socket I mean you connect once, then just send data to/from the server, rather than constantly connecting/sending/receiving/disconnecting which is what http normally does. Having a constant connection allows the server to be able to push data to the browser when it is necessary, rather than the browser having to constantly check in with the server to see if anything has changed. If there is no changes, no data is sent saving bandwidth and processor power.

 

As far as querying the chat table, that all depends on how you want to setup the server side of things. You could just have your server setup so that when someone sends a message, the server accepts it and then re-distributes it to all connected clients and never even involve a database table. This is how IRC works for example. If you wanted to store a complete chat history then you'd still need to write it to a table, but you only need to write it, not re-select it for each client.

 

Even if it does do it when new data is available a simple 10-20room chat room with all active users using socket.io wouldn't that just rape the server?

# of rooms is irrelevant. # of connected clients is what you need to be concerned with. 1 room with 100 people is the same load as 10 rooms with 10 people each, more or less. How many clients your server would be capable of supporting depends on how well the chat software is coded and server specs. A low-end VPS (512-1gig ram) should easily be able to handle a few hundred users. Depending exactly on what you need/want the chat to do obviously.

 

Would this be why sometimes if u DC you lose data on ur character because it wasn't saved to Server? (Wouldn't this need to be updated like every second as well) for no data loss?

Possibly, although just because the client disconnects does not mean the server would fail to save the data. For that to happen, something would have to happen on the server end, such as a crash or power outage.

 

How do these servers perform so good under these load, I dont get it :/

Also you need to keep in mind that these big MMO's you compare to have LOTS of servers, possibly with some pretty high-end specs. Also, keep in mind that a lot of the interaction with the database is going to be SELECT queries, just reading out things like character/mob specs, loot tables, etc. There would be quite a bit fewer write operations going on. To handle all the SELECT's you use replication to distribute the load among several different slave read-only DB servers. Write operations would be directed at the master server which then relays those changes to all the slaves.

 

Also, does every windows programmed MMO/Multiplayer  game have to use Winsock?

Every piece of windows software that connects to a network at all uses winsock. Winsock is windows' sockets implementation which drives all socket base communications.

Link to comment
Share on other sites

Okay, I feel a lot more comfortable now about thinking of socket.io and winsocket.  Thank you for such clear explanations Kicken, greatly appreciated.  I know some of these questions are kind of "Herp derp" but I'm just literally laying it all out, I don't care what people think of me anymore. 

 

 

So now that I understand socket's a bit more.  Let me see if I got it right:

 

I refresh a page with socket.io and now I am officially connected to the server.  If the server wants to output "hello world" I could tell the server to do it that via server admininstration right or a command. And it would in essense display it to all users connected?  (Same for software that uses winsock)

 

So being connected doesn't necessarily mean querying unless like you said, having a chat system with a database for storage or logging or whatnot.

 

But a simple global chat system, could just be data that is being sent to all clients connected, but doesn't really need MYSQL Or UPDATES OR any QUERYING because it's just data being outputted to everyone.  So it's more of a bandwidth usage issue in the long run? All that data of people's chat messages being sent across a active connection of 100-200 users would rape bandwidth more than mysql data/querying (since we dont need mysql unless for storage or w/e).

 

This is also why whenever I log out of some MMO's, all my message history is gone.  [but changing channels or going to character selection they stay there] using a temporary session solution most likely?

 

But yeah

 

1 Thought... 

 

For a html 5 game where the server needs to spit out the coordinates of each user on the screen (X,Y, Z) using a 300 milisecond ajax request to update everything would be terrible as in-compared to just using socket.io right? So this technology socket.io is merely the same as winsock? Winsock has been around since what 1999? Why did it take them this long  to release it for browser technology?

Edited by Monkuar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.