That describes pretty much everything I've ever done in this gameBut sometimes, you just have to learn from your own mistakes.
![Smile :)](./images/smilies/icon_e_smile.gif)
That describes pretty much everything I've ever done in this gameBut sometimes, you just have to learn from your own mistakes.
This is a lockstep architecture. If any peer would skip some action or perform two actions in a different order then the determinism is lost and the game is desynchronized. There is no way to proceed if somebody haven't collected all information about next tick. Knowing data for further ticks means nothing, because the game is unable to process these data at the moment.vtx wrote:TCP hold hostage data when detect packet lost or packet arriving before it's timeline resulting a delay before the software are aware of data. Also to speed up TCP some will tempted to turn off Naggle but the benefit is marginal as you'll need to create your own buffer system for data as the ratio Sent:receive will no longer match 1:1.
About RTT over TCP for every packet you send or receive the protocol need to ACK everything, that's the RTT I talking about. With UDP you don't need to ACK at all, I'll explain later.icedevml wrote:This is a lockstep architecture. If any peer would skip some action or perform two actions in a different order then the determinism is lost and the game is desynchronized. There is no way to proceed if somebody haven't collected all information about next tick. Knowing data for further ticks means nothing, because the game is unable to process these data at the moment.
So what would you do in case when no information is received and the retransmission is not supported at all (but redundancy is)? Kick this peer because he lost internet connection for one second and then force him to reconnect and download the map once again?
And also, you don't have to care about RTT with a single, stream, continously-open connection. These ACK packets control the connection state but are not stalling further packets from going out in any way. Thanks to ACK you are provided with retransmission features out of the box and I don't think that anybody would be able to implement such features with his own custom protocol.
But you know that ACK is just a field in the "flags" bitfield of TCP segment? So in properly configured TCP connection this:vtx wrote:Server send to client1 :
network_id:10[game_event_merged]
Client 1 :
never receive on the game tick / client will simply proceed without anydata from server and send is game_event to the server with the last network_id received 9.
server send to client 1 :
network_id:10[game_event_merged]:network_id:11[game_event_merged]
Client 1 :
received network_id:10[game_event_merged]:network_id:11[game_event_merged] proceed to the game and send back is game_event with last network_id received 11.
...
then client 1 receive network_id:10[game_event_merged] he simply drop the packet as it's allready processed.
....
Server received from client 1 is last id and remove the data from the buffer next packet send will look like
network_id:12[game_event_merged]
means exactly one packet. There is also an extension for TCP for not in-order data acknowledgement:send back is game_event with last network_id received 11
I know this article. I would like to bring up one quote:vtx wrote:here some great documentation you should read if you want :
http://gafferongames.com/networking-for ... dp-vs-tcp/
From this quote it follows that neither TCP nor UDP is recommended by the author for the case of Factorio.For realtime game data like player input and state, only the most recent data is relevant, but for other types of data, say perhaps a sequence of commands sent from one machine to another, reliability and ordering can be very important.
The temptation then is to use UDP for player input and state, and TCP for the reliable ordered data.
I will not even answer to this, because this post doesn't carry any argumentation.huwp wrote:TCP is a protocol designed for file transfer and is poorly suited to games. I won't go into details - there are plenty of publications about it - use of TCP in a game project tends to go the same way as p2p does:
"TCP is so much easier and robust, we'll just use that."
Months of unexplained bugs and unstable latency later...
"Nope nope nope nope... we should have used UDP from the start!"
There are open source libs for UDP packet management if needed. Reinventing the wheel isn't required.
Misunderstanding happens when you take a portion of text out of context. That portion of text are talking about using both TCP and UDP for a game as he explain was a very bad thing to do.icedevml wrote:
I know this article. I would like to bring up one quote:
From this quote it follows that neither TCP nor UDP is recommended by the author for the case of Factorio.For realtime game data like player input and state, only the most recent data is relevant, but for other types of data, say perhaps a sequence of commands sent from one machine to another, reliability and ordering can be very important.
The temptation then is to use UDP for player input and state, and TCP for the reliable ordered data.
But it would mean rolling the game back for the slow peer (reverting his action), which is not possible with this engine as far as I know.striepan wrote:As I understand it TCP is bad for factorio *because* of re-transmissions. In case of packet loss the server could be like: "Well bad luck for you, no player action in this tick. Send me this again and i can get you in some later tick". So the affected user might be a little unhappy, but every one else didn't notice (in case of re-transmission, if it takes too long, we get stutter) . Is this even possible with TCP where data should be ordered? Even if you managed it, it would be ugly and inefficient implementation of... a clean, custom UDP protocol.
You've already seen how this "clean, custom UDP protocol" works in reality, it was not even possible to perform map downloads with attainable speed because of mistakes. Such mistakes will obviously happen if you seriously don't have years of experience in networking and protocols.a clean, custom UDP protocol
It's not reverted, it's just applied really slowly (slow enough for a round trip to the server).icedevml wrote:rolling the game back for the slow peer (reverting his action), which is not possible with this engine as far as I know.
Slow peer? If he's too slow he can't play!But it would mean rolling the game back for the slow peer (reverting his action), which is not possible with this engine as far as I know.
Map transfers are different. There, it really makes no sense to reinvent TCP badly. This should be straightforward. Or... i could see some bittorrent library for servers with slow upload, so every client works on map transfer to be faster.You've already seen how this "clean, custom UDP protocol" works in reality, it was not even possible to perform map downloads with attainable speed because of mistakes. Such mistakes will obviously happen if you seriously don't have years of experience in networking and protocols.
Not only that. The whole world snapshot would be the whole save. How are you going to send the whole world save (which can get over 20MB even on normal size bases, let alone mega bases) within fractions of a second (fast enough so you don't have to wait seconds or minutes every time a packet fails)? Having gigabit connections all around. Basically the outcome would be pretty much exactly how it's done now, as one also gets the world state (the whole save) sent again if they desync.Chanz wrote: The only bad thing about world snapshots is the additional latency.
VoIP, Streams and FPS are very good examples for using UDP because if there's some packet loss it doesn't matter. On VoIP/Streams one hears/sees some stuttering while in a FPS, players simply walk into walls when they're having packet loss.Chanz wrote: UDP will always be the holy grail in real time communications. Its used in Voip, Streams, First-person-shooter, etc. and should be used by Factorio. Sure there can be many errors, but there are concepts to migrate for mistakes in development.
Especially for that reason I said before that I don't belive that any fancy UDP protocol would be faster than well-tweaked TCP in this case. TCP is well-understood by all network devices, while custom UDP protocol is end-to-end only. It doesn't matter on LAN but in more complicated case of course it *does*.Fahrradkette wrote:The point is, as long as one doesn't have to resend it, UDP is fine. As soon as one has to transfer a state, TCP is the protocol since _The Internet_ is aware of it.
I read that when a TCP packet is lost at an intermediate node (like somewhere in between my ISP and the server's ISP) my ISP (or his backbone provider) will resend the packet without any action from my computer or the game server.
This is what happens right now with Factorio. My dedicated server running 0.13 already DDoSed few flats.Fahrradkette wrote:I often had UDP congestion on my outgoing connection due to the need of resending lost UDP packets, it even made that sh*tty router reboot
Factorio already threads the saving logic so it compresses and saves at the same time.PacifyerGrey wrote:... 2. Multithreading. About handling of transmitting long data. I see the game is saving for pretty long time. I doubt this is because it has to write much data (I have 30 Mb save for example and it saves 3 seconds long for me). The data is structured, compressed etc. I am sure you could make use of multithreading to help with this. You can just make a memory data snapshot (takes mostly no time) and then launch a separate thread which will compress date etc so this process will have near to no effect on players. Anyways with so many parallel processes I can't get why did you not think about making use of multithreading. I laughed hard on some people with cool Core i7s who said game only uses 15% of CPU. In the modern world you should really make use of this cool processors. And for i7 users - turn god damned Hyperthreading off in your BIOS. ...