[web] How do Browser games implement 'tickers'?

Started by
39 comments, last by louissan 13 years ago
Quote:Original post by DEbig3
As opposed to a user not logging in for a week, and then having to calculate 10k updates?


I doubt this is a problem. 10k is not very much, that's just about 1 ‰ of the number of rays a very basic realtime ray tracer can trace each second. Of course a web-server is usually not fast, as are most languages when compared to non-beginner C++.

So let's assume a tick is needed once per second:

1 tick/second
= 60 ticks/minute
= 3.600 ticks/hour
= 86.400 ticks/day
= 604.800 ticks/week
= 2.419.200 ticks/(28 days)

Advice A) Benchmark how long it takes for so many ticks. If it is just 10 seconds or less, I'd say we have no problem (in case this technique is applicable)

Advice B) Do you really need 1 tick/second? In case 1 tick/(30 seconds) would be enough, e.g., you would only have 80640 ticks/(28 days). Then go back to A).

(again, this is only in case the technique is applicable and to show actual numbers)
Advertisement
Quote:Whether it calls update.php 5 times after 5 minutes of zero activity or once a minute during those 5 minutes, it's the same amount of work done by the server


This is rarely true in practice and completely wrong in theory. An operation 5 times is not equal to 1 operation that comes to the same answer. Example: Do this 5 times: n^2 = nnext, where n is initially 2. Convert the final answer to binary.

Or take 2 in binary (10) and append five 0s (1000000 = 64).

Just something to think about.

PS: Learn to use cron/task scheduler/roll your own if you go that route. Dealing with the extra overhead of triggering it via HTTP (even just the transfer costs!) isn't worth it and can easily become a MAJOR problem. What if your connection goes down? What if the server is disconnected for updates?
Ahh. I'm actually the webserver myself.

For the time being, I've just got an update.php on a META 60 second content refresh.

Later on I'll either use windows scheduler or a curlpp app.
Quote:Original post by jolid
Quote:Whether it calls update.php 5 times after 5 minutes of zero activity or once a minute during those 5 minutes, it's the same amount of work done by the server


This is rarely true in practice and completely wrong in theory. An operation 5 times is not equal to 1 operation that comes to the same answer. Example: Do this 5 times: n^2 = nnext, where n is initially 2. Convert the final answer to binary.

Or take 2 in binary (10) and append five 0s (1000000 = 64).

Just something to think about.

PS: Learn to use cron/task scheduler/roll your own if you go that route. Dealing with the extra overhead of triggering it via HTTP (even just the transfer costs!) isn't worth it and can easily become a MAJOR problem. What if your connection goes down? What if the server is disconnected for updates?


This isn't about an operation five times vs. a different operation that comes to the same answer.

This is about calling update.php once per minute for five minutes, vs. calling it 5 times in a row. I don't see a difference here.

Also I think you'd have to append 31 zeros for your example, which is really just showing that squaring numbers that are 1 followed by zeroes is easy in any base. It's not a shortcut.

Switching to a different base doesn't help you at all since you still have to do the work of converting it back to the base you're interested in which is even more work than manually squaring 2, 5 times in decimal.
Quote:Original post by sooner123
Ahh I see.

I don't see a big advantage of having the C++ application make all the updates itself over it calling an update.php. Unless C++ would simply do it far faster than PHP can. But I'd imagine in both cases the bottleneck would be the database.

Well I'll definitely weigh all the suggestions here and figure something out based on the final nature after more design fleshing. I now see that choosing between an "update when user loads a page or does something update-relevant"-solution, a "curlPP-driven C++ app that executes an update.php"-solution, and a "C++ app that updates the gamestate itself"-solution is fairly dependent on the specific nature/popularity of the game.

Ultimately I'll choose something that works without introducing any serious bottlenecks and takes the least work to implement.


Basically the drawbacks of a c++ program running curlpp is:

1) Most free/cheap hosts won't allow it, you'll have to pay for a dedicated server (Same is usually true for windows scheduler and cron) (The windows scheduler also has a lower limit of 5 minutes, atleast on Vista (not sure about server editions)

2) curlpp doesn't run update.php , it generates a HTTP request, sends it to the webserver and has the webserver parse the php script, this is unnecessary overhead.

a c++ app that updates the gamestate directly basically has the same primary drawback as the curlpp solution, it requires a dedicated server, however it has less overhead since it doesn't involve the webserver or the php parser in the update process, If you've allready written your update.php script its probably not worth the effort though.

If you got a dedicated server and know that the database will be the only bottleneck you could just run "php.exe update.php" and have update.php loop and sleep for you, this has less overhead than the curlpp solution (no webserver gets involved) and takes less effort to code (no need for c++ code, just add set_time_limit(0), an infinite loop, a time check(to ensure the correct amount of time has passed before running another update),a short sleep(to avoid eating up all cpu resources while doing nothing) to your update.php script) and a way to terminate the script cleanly (if you need to make updates to the script you don't want to kill it in the middle of an update).
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Just an FYI: The Windows scheduler's commandline interface is at.exe

(At least it was on WinNT, Win2K...)
Quote:Original post by SimonForsman
Basically the drawbacks of a c++ program running curlpp is:

1) Most free/cheap hosts won't allow it, you'll have to pay for a dedicated server (Same is usually true for windows scheduler and cron) (The windows scheduler also has a lower limit of 5 minutes, atleast on Vista (not sure about server editions)

2) curlpp doesn't run update.php , it generates a HTTP request, sends it to the webserver and has the webserver parse the php script, this is unnecessary overhead.

a c++ app that updates the gamestate directly basically has the same primary drawback as the curlpp solution, it requires a dedicated server, however it has less overhead since it doesn't involve the webserver or the php parser in the update process, If you've allready written your update.php script its probably not worth the effort though.

If you got a dedicated server and know that the database will be the only bottleneck you could just run "php.exe update.php" and have update.php loop and sleep for you, this has less overhead than the curlpp solution (no webserver gets involved) and takes less effort to code (no need for c++ code, just add set_time_limit(0), an infinite loop, a time check(to ensure the correct amount of time has passed before running another update),a short sleep(to avoid eating up all cpu resources while doing nothing) to your update.php script) and a way to terminate the script cleanly (if you need to make updates to the script you don't want to kill it in the middle of an update).


I am the server. I actually thought php scripts timed out after 30 or 60 seconds or something. Is there a way around that? Or is it different when it's executed on the command line like that?

I really like that solution. It has the cleanliness I was looking for.
Quote:Original post by sooner123
I am the server.

Huh?

Quote:I actually thought php scripts timed out after 30 or 60 seconds or something.

This is configurable. In theory, you can make that it never times out. In practice, it might depend on your hoster.
Quote:Original post by phresnel
Quote:Original post by sooner123
I am the server.

Huh?

Quote:I actually thought php scripts timed out after 30 or 60 seconds or something.

This is configurable. In theory, you can make that it never times out. In practice, it might depend on your hoster.


I am running the server.. on my own computer. I said that early on this thread but everyone seems to think I'm accessing a remote host.

If I disable timeouts.. it'll be disabled for anyone else accessing my server too?

I was hoping there was a command line argument to disable the timeout for that one call, but to leave the timeout active since it's an important feature.
Quote:Original post by sooner123
Quote:Original post by phresnel
Quote:Original post by sooner123
I am the server.

Huh?

I am running the server.. on my own computer.

My "Huh?" was targetted at that you are prolly not a server-computer, but a human running a server ;)

Quote:If I disable timeouts.. it'll be disabled for anyone else accessing my server too?

If you configure it in your php-settings, indeed.

Quote:I was hoping there was a command line argument to disable the timeout for that one call, but to leave the timeout active since it's an important feature.

According to man php, you can pass the name of a specific php.ini to it. So maybe you can grab your central php.ini, and fork your own custom configuration from it.

This topic is closed to new replies.

Advertisement