Advertisement

PHP MYSQL MMORPG

Started by December 14, 2017 03:36 PM
8 comments, last by hplus0603 6 years, 11 months ago

well, i have started developing games last year, alone , I made a singleplayer 3d openworld rpg on unity you can look at it on googleplaystore ( kooru stone rpg ) whatever, this year, i wanted to make mmo, which gone really fine until I first try real hosting, I was working on "wamp" until then. The reason i am desperate now is that the way my game works.

On my pc, using wamp mysql , with localhost as host for my game, i was testing my mmorpg with using andorid emulators, ofcourse no lag no issues no restrictions, beautiful dream... But then, I wanted to get real host from web, so, I rent a basic, cheaphest ever web host ( 10$ year ), and transferred my php files along with sql database. 

So, I launched the game, still no issues, tried to handle 2-3 players by using my pc, phone, friend's phone...  

After a while, ( after really short time (3-4mins)) host started not to respond, beacause those web hosting were not fit to handle mmos, i predicted that.

now what i am explaining is that my game works like this and asking what way should i use to handle it :

- Creates web request ( like : webhost.com/game/getplayerdata.php?ID=2 )

-Reads request ( request result be like = "ID2-GoodGuyXx-23-123-4-123-43 )

-Builds player using result string

-does similar requests REEAALY FREQUENTLY  ( total requests of 8 - 12 times per seconds )

With my current ultimate cheap web hosting, i can handle 2 players with low lag ( lol ) but, i want to handle around 20-100 players,

just need a clear path, i have been struggling with google cloud sql and other vps server dedicated server options, i dont wanna pay much and get ripped off.

-visual design

-music composing

-coding forever

Is there a reason you just don't use the Unity multiplayer services? It works almost automatically with Unity games.

I find it much easier to use than what I am trying on my own. They also have a handy way of calculating your cost:

https://unity3d.com/unity/features/multiplayer

2 hours ago, Mert Oguz said:

-does similar requests REEAALY FREQUENTLY  ( total requests of 8 - 12 times per seconds )

Aren't you in control of this?

The way I do my own requests, still learning, is by sending one large pack with the main info when the player starts. Then I update only the data that is needed.

This works better than updating at a fixed time period for me.

Advertisement
10 minutes ago, Scouting Ninja said:

Is there a reason you just don't use the Unity multiplayer services? It works almost automatically with Unity games.

I generally dislike unity servies, assets, libraries and components. I mostly force myself to build my own path.

11 minutes ago, Scouting Ninja said:
2 hours ago, Mert Oguz said:

-does similar requests REEAALY FREQUENTLY  ( total requests of 8 - 12 times per seconds )

Aren't you in control of this?

I am in control of limit of it, requests sent over time from request queue, not when needed. Im fine with it but minimum request for a second is theorically 8, if connection is perfect, players sends it's 32-character length basic data for 4 times and gets character list of basic datas 4 times.

-visual design

-music composing

-coding forever

1 hour ago, Mert Oguz said:

32-character length basic data for 4 times and gets character list of basic datas 4 times.

This looks like it can be your problem then. 32*2 = 64 bytes for the string. 64* (8 to12) = 512 to 768 bytes per second.

Most of these cheap servers have a 500 bytes per second limit for each user. You should also have a huge overhead because your not using a server optimized for games.

 

"ID2-GoodGuyXx-23-123-4-123-43 "  Looking at this example you waste a lot of data on the ID, around 50% of the data is just the ID.

Solve:

Spoiler

 

You could use a shorter ID here. A number would be more efficient. ID2-GoodGuyXx = 9999999999999; so nine billion players support for the same cost. You could even improve that by just using the ACII numbers. (A-Z, a-z, 0-9 and sybols)

128*128*128*128 = 268 435 456 IDs for just 4 string characters. A example would look like this (B1&b) and would be 8 bytes large.

 

The rest of the data your sending looks like values for resources. "23-123-4-123-43" You could again send these as the ACII number

Solve:

Spoiler

 

"23-123-4-123-43" = "W{D{+"

To read this you use:



string StringCode = "W{D{+";
foreach( char Resource in StringCode)
{
   int tempInt = Resource;
   print(Resource);
}

Don't parse it, that will not work, you need to turn it into it's int.

 

So if we use both optimizations we get: "B-W{D{+"  = User 002 has 23 123 4 123 43

7*2 = 14 bytes = 14* (8 to12) = 112 to 168 bytes per second.

So with this you should be able to connect players without breaking the limits of your small server.

 

For even more ways to pack data here is links:

https://gafferongames.com/post/reading_and_writing_packets/ given by @Kylotan

https://www.gamasutra.com/view/feature/131503/1500_archers_on_a_288_network_.php given by @Hodgman

In this topic:

https://www.gamedev.net/forums/topic/693525-how-to-reduce-data-sizes/

 

Edit:

I just want to point out that running your game with Unity's services would cost $30.

well the way you take it really impressed me, I was thinking of compressing the data latetly but I didnt think of using characters for numbers, , I may, mess it up a lil bit while working on this since there are some high/negative numbers but still when in numbers it doesnt excess 32 char limit in the end its fine.

um so... 10 $ -year host to handle mmo challenge accepted ?

lol not really since i am even getting lazy start connections on mainmenu.

just a "better but not best" web host can handle this i believe?

thanks so much for replying me and pointing an essential issue, I will do my best with data compressing. 

-visual design

-music composing

-coding forever

Quote

-does similar requests REEAALY FREQUENTLY  ( total requests of 8 - 12 times per seconds )

I think this is the problem. Trying to use MySQL as a messaging layer is extremely inefficient. Cheap web hosts have thousands of people share the database, and trying to add more queries will not work. I don't think bandwidth is your main problem.

First, you'll want to use a real web host. You can use Amazon Lightsail for $10/month, or Linode for $10/month, or something like that. You will have enough CPU power and memory to run small servers on those hosts under your own control. You will also get enough network bandwidth that you don't need to worry about that as a limitation.

Second, you may be able to get to 10 players on such a server using the mechanism you have; you may even be able to throw more money at it and get to 100 players using MySQL (at potentially hundreds of dollars per month per server.) But that's a waste of money.

You'll want to use a server that doesn't need a database to answer most questions. The way to make that happen, is to use a server stack where the server has memory and persistence. PHP doesn't do this, but servers like Node.js or golang do (as well as Java, C++, C#, and other such languages.) You can also get persistent servers in Python. You can still use HTTP for your protocol -- it's not very efficient, but it can be made to work. (Websockets would be better.) But, make the queries go to data in RAM, and respond based on data in RAM, rather than the database. Instead, only read from a database when the player first logs in, and write back to the database when data that really matters changes (inventory change, trade, experience gain, those kinds of things.) This will keep the database much less overloaded.

64* (8 to12) = 512 to 768 bytes per second. ... Most of these cheap servers have a 500 bytes per second limit for each user.

I doubt this is accurate information. Each web request will have more headers than just the request URL, and each response will have a lot more headers than just the payload data. And I've never seen a cheap web host that intentionally limits the bandwidth per user, although they sure do oversubscribe their network interfaces, so how much data you can get through depends a lot on how busy other users on the same host is.

I highly recommend starting with a virtual private server from Lightsail or Linode or Dreamhost VPS or Interserver, and you have the ability to scale up from there.

enum Bool { True, False, FileNotFound };
Advertisement

I have reduced those calls from the game to 3-5 times per second, i have made my all web requests on a single queue that whatever you do, its send when queue clock in up to ready for that job. ( that means, in worst case, player can send 5 requests max in a second ) I have tried to login the game from 4 diffrent devices and it was fine but lil laggy. ( even lags when playing solo though lol )

I am sure that i need to manage those stuff definetly not with a web hosting service. Also I asked to my web host tech service that" Just after i bought the service, there was no issue with connections( no lag) i am building an application that is used from mobile android devices so if this service does not fit what should i do?"

And they replied back like, "you cant use it from applications its not supported, try cloud servers"

If somebody knows what does that mean? What i am saying is I can currently play the game actually with 4 players, and even right after I transfered my game to their host, connection was almost perfect. Do they put a connection barrier ? So if i get a non-shared web hosting, will i be able to handle the game actually?

I would really like to change the way my system works though, i have worked on a firm that makes trading web sites with asp.net using c# but for mmo, i looked up on web and i thought it could be light and fast to choose php mysql. I am totally noob on this stuff. 

And to prevent "cheat engine-like" hacking i have made restrictions on requests so players wont be sending their data from client to update directly, there are some extra queries in php files to first find player with account id then compare some stuff. Maybe that also could be the reason of slow responds.

Currently the happening thing after player enters to the map is,

1) loads everyone in the same instance, with their main and basic data "once". 32+32 strings for each player ( will compress that soon )

2) every 0.3 seconds, updates your basic data along with loading others basic data. 

3) after each '4 basic updates', runs a check instance to look for dates(32 string each player) wheter someone entered or left or disconnected.

 

 

-visual design

-music composing

-coding forever

7 hours ago, hplus0603 said:

And I've never seen a cheap web host that intentionally limits the bandwidth per user,

Sorry if I wasn't clear on that. I didn't mean the host limits the bandwidth. I meant that the allowed bandwidth / players. Also I know it isn't as simple as that; that is why I mentioned the overhead for servers that isn't made for hosting games; all though I don't exactly know what it is.

I am really new to this.

7 hours ago, hplus0603 said:

First, you'll want to use a real web host.

Could you explain the difference between web host like Amazon Lightsail and others. I think many of us new to multiplayer games end up paying for the wrong services.

If somebody knows what does that mean?

They seem to claim that they only expect you to make web pages on their service, and any kind of application/web service that makes API calls are unlikely to work well on their service.

Could you explain the difference between web host like Amazon Lightsail and others

There are "shared web servers" -- these are the cheapest, and is the kind that the OP initially set up.

These give you a directory to upload your web files to. Those web files might be intended for some particular web development language (PHP, Ruby, Python, etc) and typically use a "one request is one process" model. You receive a HTTP request, you do whatever queries and processing you need to do (if any) and you respond with a web page or some other web resource (image, XML, JSON, ...) You cannot upload code that's not supported by the web server host -- you can't build your own C code for processing network requests -- and you cannot run processes that stay alive for longer times, talking to many players at the same time.

These are okay for "my own photo album" or "jimmy's pizza ordering page." If the page sometimes takes a second or two to load, that's not a big deal. All the traffic goes over HTTP,  which is a request/response, bulk transfer protocol on top of TCP,  with no particular guarantees around latency. Also, typically there are 1000s of "home directories" on each of these servers, serving a bunch of different, small, web pages all at once. (The server knows which directory to look in based on the URL and Host: header in the HTTP request.)

 

Then, there are "metal servers" -- a computer is plugged in to the network, and has an OS on it, and you get administrator/root access. It's up to you to make sure the hard disks are partitioned the way you want them, that the software you need to run on there is installed, and that security exploits get patched. You can build whatever software you want and install on these servers. For action games, which almost always use UDP networking, this is great, because you can spin up a game server on a known port, and point game clients at this server/port. Draw-backs are that you need to be much more aware of how to administer servers in a safe, secure, and efficient manner.

In addition to game servers, web sites that are bigger than suitable for a shared web host can use one of these servers (or more) and install their own web server and database server as the software that runs on these servers. This allows you to avoid the "noisy neighbors" problem of shared web hosts.

Because these servers are a full computer that costs a lot of money to buy, server hosting companies will charge significantly more per server instance. Typically a few hundred per month, at least (more if you want fancy memory / RAID disks / multiple CPUs and so on.)

 

Then, there's an intermediate step. You don't need a big server with 256 GB of RAM and a 10 TB flash RAID array and dual 10 Gbps uplinks to the router. You just need some fraction of that -- one or two cores, one or a few gigabytes of RAM, a dozen gigabytes of disk space for your software, and a terabyte or two of network transfer per month. You're OK with sharing the same physical hardware with others, as long as you get the guaranteed memory and processing power that you pay for. Various "virtual private server" ("VPS") solutions deliver this kind of server. For most intents and purposes, it "looks like" a small metal server (and has some of the same problems of needing security patches, administration, and so forth,) but the cost of actually sticking hardware in a rack in a data center is spread across many people who each share a defined portion of the server. Thus, this is cheaper per month than a full server.

This is what Amazon Lightsail, Linode, Dreamhost VPS, and Interserver end up selling you. Amazon has the best name in the business and the most mature set of infrastructure tools, and thus charges the most. Dreamhost has a business that's more around easy-to-manage web sites, and provide a lot of value-add if you use their software versions, and thus charge extra for that. (They also have shared web hosting.) Linode gives you a little more than Amazon for your money, while having a smaller variety of tools around their images, but are still a well-known actor with some really big customers. And, finally places like Interserver is just "give me a server and get out of the way" bare bones, which lets you get down in price a few more dollars at the bottom end. On the other hand, their data centers and internet uplinks are more oversubscribed than Linode or Amazon -- you get what you pay for.

There are of course many more online server providers of various kinds -- Heroku, 1and1, Peer1, ServerBeach, Rackspace, and the list goes on. The four above are the ones that I have direct experience with that has been good enough to recommend if you need their particular kind of service.

 

Once you outgrow VPS/cloud solutions and metal-leased servers, you will build your own data centers in some co-location facility, negotiate for bandwidth with upstream providers like Cogent and Level3, and screw your own servers into your own (rented) racks, where you have to build your own in-datacenter network infrastructure (routed or switched? Overprovisioned or nonblocking?) and have to worry about things like power density (130W CPUs perform great, but if you try to cram two of them per motherboard times 42 of them in a rack, you will draw more power than most power distribution and cooling will let you get away with -- are watercooled racks worth it?) Co-location is cool and all (or, if you're facebook/google, you build your entirely own data centers) but very few indie games grow to the point where they need to worry about that. Find a VPS vendor you can trust (linode or amazon) and stay there for as long as you can.

 

 

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement