OneLife icon indicating copy to clipboard operation
OneLife copied to clipboard

Lag in cities

Open Stylingirl opened this issue 8 years ago • 13 comments

Many player reports about lag and disconnection issues, especially in bigger towns with larger populations.

Stylingirl avatar Nov 09 '18 04:11 Stylingirl

There are two things here:

  1. Can their graphics card keep up with everything that needs to be drawn? If not, they will get FPS lag.

  2. Can their network keep up with all the information that they need to receive?

Both 1 and 2 are more of a problem in very busy areas.

jasonrohrer avatar Nov 09 '18 23:11 jasonrohrer

Is this entirely a client side issue? If it's server sided too there's at least one optimization that would help. Since player updates get sent to every other player, the load increases exponentially as player counts rise. So the typical method is making a grid system that players are put into based off of location, and then when player updates are sent out, the server grabs the the square the players in, and the ones surrounding it, and sends the updates only to the players inside those squares.

Dylan-Floyd avatar Nov 19 '18 09:11 Dylan-Floyd

I had the same issue on a big city and I have both a good network and gpu. Some others players were complaining about lag, but not all of them.

marcel0ll avatar Nov 19 '18 17:11 marcel0ll

Tapeman, yeah, the server already does this. Only sends you updates about players that are in your immediate area.

0tho, again, what kind of lag? FPS lag (people walking slow) or action lag (bouncing when you go to do something).

jasonrohrer avatar Nov 30 '18 21:11 jasonrohrer

I had action lag, other people appeared to move and act normally, although some other players were also complaining about lag, which I assume was also action lag. To my point of view only my actions were not being executed properly. This even caused my old age character to starve as I as not able to tell her to eat.

marcel0ll avatar Dec 03 '18 13:12 marcel0ll

What kind of connection are you playing on?

I wonder if for some people, a heavy downstream flow of messages from the server (in a busy city) is interfering with their upstream messages getting back to the server.

jasonrohrer avatar Dec 10 '18 19:12 jasonrohrer

There's a new feature in the game now that you can use to diagnose lag.

In the chat box, type either:

/fps

or

/ping

This will show an FPS meter (to help you diagnose GPU lag---you should see a solid 60 or whatever your target FPS is), or ping the server (you should see a response time that is less than... 400ms.... no matter where you are in the world).

jasonrohrer avatar Jan 03 '19 17:01 jasonrohrer

I also see this issue pretty deterministically in bigger camps. In these cases, /ping increases from a normal ~190ms (from Europe) to > 1 second (sometimes several seconds). CPU (< 10 %) and network usage (< 100 kB/s) is low at these times.

I captured a tcpdump and filtered for ping/pong frames ohol_ping_pong_packets.pcap.gz

What is interesting here is that the server seems to respond in time. E.g. PING 15 was shown as ~900ms but the PONG was received ~170ms after the PING so it seems to be a client issue (good for you, I guess ;) ).

I run a somewhat weird setup driving a 4k screen on Linux with ~25 Hz so that might be related or not (I'm getting a vsync warning on the start screen). It wouldn't explain why it is slow with many people / big camps.

jrudolph avatar Jan 16 '19 20:01 jrudolph

I also see this issue pretty deterministically in bigger camps. In these cases, /ping increases from a normal ~190ms (from Europe) to > 1 second (sometimes several seconds). CPU (< 10 %) and network usage (< 100 kB/s) is low at these times.

I can confirm. In my case however, the ping goes way beyond just a second, usually sits between 6 and 8 whole seconds, making the game unplayable. Moving away from the town completely stops the latency (when it is happening). Personally this started to happen as soon as the big server tests took place and never stopped since then. As for my FPS, yes I do get FPS lag when in a big town with a bunch of people doing stuff around but that has never been a problem previous to the big server tests. I should also mention that I'm always using my slow motion fix so I'm not really affected by FPS lag, it just looks a bit choppy.

Leonard2 avatar Feb 01 '19 20:02 Leonard2

In case this is helpful, I was playing side-by side with another player as twins yesterday. We both had no issues when playing in towns of normal population. When we were born into a bustling town with 20+ people on two screens and 40+ people on four screens, we both experienced significant lag. My twin's lag was immediate and extensive, on the order of multiple seconds, while mine was unnoticable at first, but slowly increased into an approximately one second delay. The delay was especially noticeable when I placed or picked up items, like baskets. My twin died due to the lag, and respawned as a baby in the same city. We both noticed that his mother appeared to be teleporting him around when she would pick him up and move him to a different location. Let me know if it would be helpful to provide family tree links for these characters.

BlueDiamondAvatar avatar Feb 03 '19 16:02 BlueDiamondAvatar

I put a few printf's into the client and found something weird. Every time data is read from the socket, I print the total amount of data in the serverSocketBuffer. When the ping gets high and the game gets laggy, it seems the data in the buffer seems to accrue for a while, leading to lag because the buffer isn't promptly processed.

I don't know much about the game code but I think I tracked it down to the behavior of getNextServerMessage. It seems while the game is waiting for an FM message, it always only reads a single message from the buffer and the returns NULL:

https://github.com/jasonrohrer/OneLife/blob/072f276575bbaea579f7052c81eec0698fce25af/gameSource/LivingLifePage.cpp#L1149-L1169

That means, while waiting for FM only ever a single message is read from the socket buffer and pushed to the serverFrameMessages. Because getNextServerMessage is called only once from step (if it returns NULL), this means the rate of messages the client reads from the buffer (while waiting for FM) is limited by the rate that step runs. PONG message are supposed to be expedited but by the same logic they are stuck in the buffer the same way.

I wondered why there's not more people that complain about the lag and I (wildly) guess that's because step is synced to your frame rate, which means that there's an artificial hard limit of messages that the client can receive depending on your frame rate. As I mentioned before my machine can drive my 4k monitor only at ~25Hz which is slower than what most machines would handle, so that would make it more likely that it's a problem for me.

Luckily it seems the problem is easily solved. While waiting for FM just make sure to process all of the buffer for every invocation:

diff --git a/gameSource/LivingLifePage.cpp b/gameSource/LivingLifePage.cpp
index a25f8792..df83e08e 100644
--- a/gameSource/LivingLifePage.cpp
+++ b/gameSource/LivingLifePage.cpp
@@ -1119,7 +1126,7 @@ char *getNextServerMessage() {
 
             char *message = getNextServerMessageRaw();
 
-            if( message != NULL ) {
+            while( message != NULL ) {
                 messageType t = getMessageType( message );
 
                 if( strstr( message, "FM" ) == message ) {
@@ -1128,6 +1135,7 @@ char *getNextServerMessage() {
 
                     if( serverFrameMessages.size() > 0 ) {
                         serverFrameReady = true;
+                        break;
                         }
                     }
                 else if( t == MAP_CHUNK ||
@@ -1151,6 +1159,8 @@ char *getNextServerMessage() {
                     // keep it
                     serverFrameMessages.push_back( message );
                     }
+
+                    message = getNextServerMessageRaw();
                 }
             }

jrudolph avatar Feb 04 '19 08:02 jrudolph

jrudolph, you really saved my hide here!

Been working on this mystery all day, and then someone told me you figured it out.

Will take a closer look tomorrow.

jasonrohrer avatar Feb 09 '19 04:02 jasonrohrer

Yay, glad I could help!

jrudolph avatar Feb 10 '19 14:02 jrudolph