Hello again friends and strangers alike.
I forgot it's been 2 weeks yesterday, only just remembered it hehe!
This time we have optimized the server and redesigned world storage a lot among other things.
Here's the changes since last time:
- We now use AES instead of XTEA (with old XTEA backwards compatibility)
- We've made the server many many times faster than before with all kind of changes/optimizations
- Server now takes in up to N cores (the number YOU want can be set in config, I like this number though for stability) number of players every gameround, for me this is 16 x 50 per second or up to 800 players, but in reality server can't handle taking in more than up to ~400 players per second, I haven't actually profiled this so I don't know why not more - maybe the SQL? Maybe the file parsing? Maybe a combination of all that + RSA? I'm not sure
- Mass login script is more functional now (and also supports AES)
- We get 0.1s of lagg every gameround with 5k players on all turning every second after optimizations
- After these optimizations we used 3G of memory instead of ~1.2G by using nested vectors
- Then we reduced it back down to 1.2G by switching to C arrays
- Further reduced it down to 1.1G by implementing the class "CheapVector" for creature positions
- We tested logging in 9000 players (not the max number, I just arbitrarily picked 9000 after 5000); it works, but ~1s lagg every gameround, so the game is not really playable with this many players
Couple of notes:
1.
To be clear: the 9000 players were, yes, all online at the same time.
I will maybe make a youtube video about it later.
But while the CPU lag was only ~1s every gameround, the actual network/server interaction lag was more like ~10s.
This might have been however because we made the main thread sleep too short in between gamerounds, not allowing enough packet flow in.
I'm not sure, but I've since changed the minimum sleep amount to a higher number, but haven't tested whether the lag is any better.
We can see monsters moving every second or so, but we can't actually move, almost like a DDoS attack.
Doing some quick math, I'm not sure, but the network traffic could easily surpass the MB/s of the local network interface, which I believe is usually measured in mbit/s, not MB.
That's another possibility, either way - 9k players online is unplayable.
2. There's one (semi-big) limitation now with map traversal, that we see with oldschool Real Tibia too.
Namely: players/actually any creature can't step on empty (black) tiles anymore.
As it is right now, the server will in fact segfault if you do, but this will be fixed by the next update (instead it will simply not allow you to step on the tile).
This is why most likely Gamemasters and Gods on Real Tibia can/could only teleport to "safe"/existing tiles.
This was necessary for the server to be optimized to handle possibly up to ~5k players online at the same time without much noticable lag.
In fact it's actually impossible using C arrays to create the tiles even if we wanted to (which I kind of do want to).
Because the position of tiles on NEGATIVE offsets is either a negative number (non-indexable) or overflows to 65535, which is an impossibly large number of tiles to actually store.
Even with just empty pointers, calloc'ing 65535 x 65535 x 16 tiles is 68GB of memory, way out of scope for any reasonable server.
The only other option is using what I used before - a hash for player creatures, but this severely limits CPU performance / the number of players we can host simultaneously.
In fact the reason why I switched to C arrays was almost only to optimize gameGetPlayers, which is the server's last bottleneck at ~70% of the CPU usage.
So yes, well, that's about it.
Until next time, take care ya'll!