ELI5: Why does multiplayer bog down my cpu?

Post all other topics which do not belong to any other category.
Post Reply
User avatar
Jon8RFC
Filter Inserter
Filter Inserter
Posts: 553
Joined: Tue May 10, 2016 3:39 pm
Contact:

ELI5: Why does multiplayer bog down my cpu?

Post by Jon8RFC »

Harkonnen wrote:Multiplayer is different in sense that you must catch up with the server all the time, so when you reach 60ups margin, game starts sacrificing rendering frames to stay on same pace with the server. This is a big issue to solve for us because server is frequently a dedicated machine faster than any laptops connecting and server running in headless mode does not have to render anything, so catching up with it is quite a quest on its own. Right now players solve this problem by slowing down game deliberately with something like "/c game.speed=0.9", and further on as game drops below and below 60 ups. The right solution would be to perform some automatic game speed adjustment on server side, we have plans for that.
I'm at a loss for understanding this, and would really appreciate some insight because on the surface this explanation makes no sense to me.

I fully understand the simple part--if my cpu simply can't run a map at 60ups, it's likely to be because there are too many calculations necessary to process at a given time and it just can't keep up. That's easy to understand.

If there are a finite number of calculations to process at a given time, why am I able to save the map locally and never run into this issue on those same mega-bases that give me a problem when connected to the multiplayer server? There would be additional players on the server in these instances, but never more than about 20, and sometimes only about 5. I have a hard time understanding if those few players (most of whom are just running around or doing minor maintenance) can cause such a substantial increase in the number of calculations necessary to process through, compared to the mega base itself, especially when the explanation is simply that a 7700k is faster than a q9550.

I'm just very stuck on the logistics of why a faster cpu can run a particular mega-base at 60ups, my cpu can save and run the same mega-base locally at 60fps and 60ups just fine, yet when my computer connects to the "faster server", it can no longer run at 60ups on the same mega-base "because the server is faster." What that sounds like, to me, is that "going 60kph in a Ferrari with groceries in the trunk is a substantially faster speed than going 60kph in a Honda with those exact same groceries in the trunk" and I'm really struggling to understand this concept because I'm not a software engineer. Any takers willing to help me understand this?
Image

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5156
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: ELI5: Why does multiplayer bog down my cpu?

Post by Klonan »

Jon8RFC wrote:
Harkonnen wrote:Multiplayer is different in sense that you must catch up with the server all the time, so when you reach 60ups margin, game starts sacrificing rendering frames to stay on same pace with the server. This is a big issue to solve for us because server is frequently a dedicated machine faster than any laptops connecting and server running in headless mode does not have to render anything, so catching up with it is quite a quest on its own. Right now players solve this problem by slowing down game deliberately with something like "/c game.speed=0.9", and further on as game drops below and below 60 ups. The right solution would be to perform some automatic game speed adjustment on server side, we have plans for that.
I'm at a loss for understanding this, and would really appreciate some insight because on the surface this explanation makes no sense to me.

I fully understand the simple part--if my cpu simply can't run a map at 60ups, it's likely to be because there are too many calculations necessary to process at a given time and it just can't keep up. That's easy to understand.

If there are a finite number of calculations to process at a given time, why am I able to save the map locally and never run into this issue on those same mega-bases that give me a problem when connected to the multiplayer server? There would be additional players on the server in these instances, but never more than about 20, and sometimes only about 5. I have a hard time understanding if those few players (most of whom are just running around or doing minor maintenance) can cause such a substantial increase in the number of calculations necessary to process through, compared to the mega base itself, especially when the explanation is that cpu speed is the issue.

I'm just very stuck on the logistics of why a faster cpu can run a particular mega-base at 60ups, my cpu can save and run the same mega-base locally at 60fps and 60ups just fine, yet when my computer connects to the "faster server", it can no longer run at 60ups on the same mega-base "because the server is faster." What that sounds like, to me, is that "going 60kph in a Ferrari with groceries in the trunk is a substantially faster speed than going 60kph in a Honda with those exact same groceries in the trunk" and I'm really struggling to understand this concept because I'm not a software engineer. Any takers willing to help me understand this?

Theres a lot of extra logic in multiplayer, and also some secondary reasons why it slows the game more:
  • More players to simulate
  • CRC checks to detect desyncs
  • Networking and packet management logic
And the biggest indirect reason:

More players using resources keeps more of the factory running, more mining outposts, more players exploring the map and generating new chunks, more players going out and fighting biters etc.
So for instance if everyone left but you on the server, after a while the factory would start shutting down, and production lines would go inactive, and you would be able to keep up.

User avatar
Jon8RFC
Filter Inserter
Filter Inserter
Posts: 553
Joined: Tue May 10, 2016 3:39 pm
Contact:

Re: ELI5: Why does multiplayer bog down my cpu?

Post by Jon8RFC »

Ah ha! Thank you for explaining all of that.

With regard to the CRC checks, is that pretty cpu-intensive compared to the other additional things? Is it basically running normally as it would locally, but in a way it's running things through twice, by confirming the outcomes of everything?
Image

Daid
Fast Inserter
Fast Inserter
Posts: 163
Joined: Sun Jul 03, 2016 7:42 am
Contact:

Re: ELI5: Why does multiplayer bog down my cpu?

Post by Daid »

Even if you can run the map at 60UPS, the server is also running the map at 60UPS.

The whole "catching up part" is fixing the time between you getting all the data for the map in a specific state, and the current time, for this, the game most likely has to simulate faster then the server, else it will just be running at the same speed and never catch up.

So, if the map takes 3 minutes to transfer, and the server is running at 60UPS, you are behind by 10800UPS by the time you are loaded. If your game only runs at 61UPS to catch up, you only catch up 1UPS per second, so you need 10800 seconds to catch up (3 hours). If you can run at 70UPS, this is reduced to 18minutes, which is still a long time to connect...

That's when you are initially connecting.

When you are connected, you are running the same simulation as on the server. With the server being ahead. But you still need to keep in sync, I can immagine that what can happen, is that a data packet which explains a change in game state is received after that point in time already happend on your machine. In which case Factorio has to roll back and catch up again, not sure if this is how it works. Other option would be that it would only simulate the next step when the server has told everything that has happened "game changing" for that update. Which (due to network traffic being network traffic) arrive randomly in time. Meaning you are always playing "catch up", and catching up takes more resources, even if you wasted time before waiting for data that arrived late.

(I don't know anything directly of the Factorio code. But I know a bit about software engineering)

slayith
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Jul 10, 2017 5:15 pm
Contact:

Re: ELI5: Why does multiplayer bog down my cpu?

Post by slayith »

Try running the server on your pc and have them connect. Factorio presents issues with the client "keeping up" with the server when the servers processing is much greater. I run 6 dedicated factorio servers on a 3rd gen i3

BenSeidel
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue Jun 28, 2016 1:44 am
Contact:

Re: ELI5: Why does multiplayer bog down my cpu?

Post by BenSeidel »

Klonan's explanation is correct, except the part about more resources as I'm assuming you have taken the save and compared results immediately after loading and not some time after when things have started to run out.

You can test this by running it in multiplayer and hosting it yourself. You don't need anyone to connect. Once the game is loaded you can press <F5> to bring up the performance stats. It's a list of the processes that need to occur in Factorio and the amount of time that is being spent on each task in ms. Running the game at 60/60 means that you have about 16ms per frame to update. If you are running at >16ms "Update time", you will be dropping frames.

The multiplayer only part is the "CRC" function. On big maps this usually runs at about 0.2 ms. It may not seem like much, but it could be enough to push you from 60/60 to 59/59 and requiring you to catch up with the server. No doubt there are some other multiplayer only functions, but I don't know for sure what ones they are or if they appear on the list. Someone else may be able to expand on this if required.

Post Reply

Return to “General discussion”