Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualsamoth

Posted 03 July 2013 - 07:25 AM

In some MMO games which are based on UDP (DC Universe for example) server works all the time. That means that there are a lot of objects created and destroyed during server's lifetime. If they increase ID of new objects by 1 all the time, the ID would eventually exceed the maximum value and would cause server crash I guess.

 

First, the server will not crash (not necessarily, anyway) if you exceed the maximum value. What will happen is that the number will wrap around (overflow).

 

That, by itself, does not do anything special (not on any real, existing computer, anyway -- in theory there could exist CPUs that generate a trap on overflow). Of course you do have the problem that you will "reuse" old IDs, but that is no problem if they have been destroyed already. Running against physical memory limits (considering 4 billion game objects with a 32-bit ID!) is much more likely to happen, and much sooner.

You do need to make sure that you remember which indices have been deleted, if you want to be safe (in the easiest case, by remembering the lowest valid index, otherwise via a freelist or similar).

 

Quite likely, relying onto "luck" will work just fine, too (because you just don't create that many objects that fast), but I'd recommend doing it properly anyway. Relying on luck is rarely a good idea, if something can go wrong, it will eventually go wrong too (maybe in a few years when nobody remembers why).

 

Depending on what representation you use for your ID, overflow happens considerably sooner or later. Assuming your server creates a 10,000 new objects per second (which is an awful lot!), a 16-bit ID will overflow in 6 1/2 seconds, and a 32-bit ID will overflow after 23 hours, 18 minutes. A 64-bit ID will not overflow during your lifetime, or during the likely remaining existence of mankind on this planet. That is, unless you deem it reasonable to expect that we haven't had World War III, or otherwise completely destroyed the planet in 58 million years from now, and that your computer program is still running by then.

 

With that in mind, if you can't be bothered to keep track of used and freed IDs, use a 64-bit ID (or use a 48-bit ID and assume that the the server will reboot at least once every 800 years!). You'll never have to worry. Of course it eats up a few extra bytes of storage, but since most IDs that appear together will be very similar except in the last few bits, you can compress those away.


#1samoth

Posted 03 July 2013 - 07:21 AM

In some MMO games which are based on UDP (DC Universe for example) server works all the time. That means that there are a lot of objects created and destroyed during server's lifetime. If they increase ID of new objects by 1 all the time, the ID would eventually exceed the maximum value and would cause server crash I guess.

 

First, the server will not crash (not necessarily, anyway) if you exceed the maximum value. What will happen is that the number will wrap around (overflow).

 

That, by itself, does not do anything special (not on any real, existing computer, anyway -- in theory there could exist CPUs that generate a trap on overflow). Of course you do have the problem that you will "reuse" old IDs, but that is no problem if they have been destroyed already. Running against physical memory limits (considering 4 billion game objects with a 32-bit ID!) is much more likely to happen, and much sooner.

You do need to make sure that you remember which indices have been deleted, if you want to be safe (in the easiest case, by remembering the lowest valid index, otherwise via a freelist or similar).

 

Quite likely, relying onto "luck" will work just fine, too (because you just don't create that many objects that fast), but I'd recommend doing it properly anyway. Relying on luck is rarely a good idea, if something can go wrong, it will eventually go wrong too (maybe in a few years when nobody remembers why).

 

Depending on what representation you use for your ID, overflow happens considerably sooner or later. Assuming your server creates a 10,000 new objects per second (which is an awful lot!), a 16-bit ID will overflow in 6 1/2 seconds, and a 32-bit ID will overflow after 23 hours, 18 minutes. A 64-bit ID will not overflow during your lifetime, or during the likely remaining existence of mankind on this planet. That is, unless you deem it reasonable to expect that we haven't had World War III, or otherwise completely destroyed the planet in 58 million years from now, and that your computer program is still running by then.


PARTNERS