[Engine] A possible optimisation for desync recovery

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

spazza360
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Nov 30, 2014 5:58 am
Contact:

[Engine] A possible optimisation for desync recovery

Post by spazza360 »

After playing 100+ hours with friends in multiplayer over the internet, I've experienced far too many desyncs, all of which take several minutes on larger maps due to a slow connection.
I believe there is room for a optimisation to the basic desync routine, involving some simple processing of the map prior to redistributing the map to the desynchronised player.

For those that don't quite understand how the game figures out when something goes wrong, it goes a little something like this:
-Every few ticks, the game checks if the map is the same on each players computer; This is called a CRC check.
-If the map (CRC) somehow doesn't match up, the game will pause and redownload the entire map again. This can take a rather long time when playing on slow internet connections.
-The game will unpause, and attempt to keep playing like normal, but sometimes the game will desync again due to the exact same error as last time, causing a desync loop.

In order to fix this long series of waiting for the redownload to finish, I have come up with the following idea:
When a desync does occur, it should be possible to do a quick CRC check for each 'chunk' and redistribute only the desynchronised chunks to the other players, and then rebuild the correct chunks into the existing map. Not only would this save transfer time, up to several minutes; but also bandwidth for having to send large (20MB+) maps over the internet, at the expense of some very short CPU processing time.

My basic programming knowledge indicates that this should not be too difficult to implement, but I don't know anything about the engine's existing implementation, so this may be incorrect.
MF-
Smart Inserter
Smart Inserter
Posts: 1235
Joined: Sun Feb 24, 2013 12:07 am
Contact:

Re: [Engine] A possible optimisation for desync recovery

Post by MF- »

Search first!
I have already linked some relevant threads to someone else here: https://forums.factorio.com/forum/vie ... 393#p51393
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: [Engine] A possible optimisation for desync recovery

Post by ssilk »

Well, this is the basic underlaying idea, but of course Merkle trees are better.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
spazza360
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sun Nov 30, 2014 5:58 am
Contact:

Re: [Engine] A possible optimisation for desync recovery

Post by spazza360 »

MF- wrote:Search first!
Well I did, I looked through several suggestion pages and didn't notice anything that seemed similar, so I thought it was a new idea.
That's my mistake, I'll check more thoroughly next time.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: [Engine] A possible optimisation for desync recovery

Post by bobingabout »

Several minutes on a large map?

I've been playing with a friend on a small map, fortunately we havn't played long enough to start getting desyncs yet, but, it's basically "Okay, I'm connecting now, go make a cup of tea, take your time", because it takes about 15 mins to transfer.



But I agree, in fact I've sugested similar things before, try sending only the parts that need fixing, not everything, I think something that one of the Devs said to me was that the reason why they re-send everything, is because of what is known as the butterfly effect, one tiny little change can ripple, and ripple, and ripple, and change the entire world before you know it.

An example: Peice of coal doesn't make it into a boiler at the same time. Power levels then differ for each player, this causes factories to run a little slower for one player, causing all produced goods to be out of sync. If that power grid covers an entire base, the entire base is then out of sync.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Tinyboss
Filter Inserter
Filter Inserter
Posts: 467
Joined: Sun Nov 16, 2014 12:11 pm
Contact:

Re: [Engine] A possible optimisation for desync recovery

Post by Tinyboss »

bobingabout wrote:But I agree, in fact I've sugested similar things before, try sending only the parts that need fixing, not everything, I think something that one of the Devs said to me was that the reason why they re-send everything, is because of what is known as the butterfly effect, one tiny little change can ripple, and ripple, and ripple, and change the entire world before you know it.

An example: Peice of coal doesn't make it into a boiler at the same time. Power levels then differ for each player, this causes factories to run a little slower for one player, causing all produced goods to be out of sync. If that power grid covers an entire base, the entire base is then out of sync.
Maybe instead of breaking it up by geographic chunks, then, the save file should be broken up into pieces that don't have this kind of dense interdependence. For instance, the placement of buildings is not likely to change in response to a power fluctuation. The terrain even less so. Mainly it would be power states, inventories, inserters, and items on the ground/belts that would experience this butterly effect, I would guess.

(1) CRC check for the terrain. This would never fail in the absence of terrain-altering mods.
(2) CRC for stationary built items like belts, inserters, buildings. Only their location and settings (e.g. filters, recipes, modules present). This one would rarely fail since changing these things is not automated.
(3) CRC for everything else. When this fails, you just send this "chunk".

I don't know how much of the save file consists of 1 and 2, versus 3. But it could save some bandwidth, I think.

Of course, if the devs feel like a totally deterministic simulation is a reachable goal, then it's probably best to focus on squashing non-determinism bugs rather than working harder to tolerate them. They're the only ones who will know how to strike that balance.
Post Reply

Return to “Ideas and Suggestions”