Search Unity

Network gets jammed - slowing down

Discussion in 'Scripting' started by Dark-Protocol, Aug 31, 2014.

  1. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    I made a basic file sharing with Unity where machines send chunks of byte arrays between each other.
    The problem is that after several sendings, the file sharing becomes really slow. I'm monitoring the network usage of the application through Task Manager and I notice that the speed decreases constantly. It starts off with 15 Mbps and it drops down to 0.2 Mbps every time (doesn't go lower). I tried sending different sized chunks but every time this happens - the file transfer gets slower and slower.

    I tested this on various networks and machines and the same issue persists so no, it can't be my LAN or router.

    I browsed answers and the forum to see if somebody else has had this issue and I found it:
    http://answers.unity3d.com/questions/487787/rpc-calls-are-slowing-down-exponentially.html

    Unfortunately, that guy doesn't know how he has fixed it. I'm starting to think that this may be a bug in Unity's networking. Has somebody else had this problem ? Does anybody have any clue of what can be causing this ?
     
  2. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Some new info on the issue:
    If a player disconnects and reconnects, the speed of the file transfer gets fast again and starts to slow down as usual. I tried to reduce the info I'm sending using the RPCs and I managed to do that but the speed keeps falling.
    Also: I found out that sending several chunks and waiting for response from the receiver and then sending more chunks doesn't impact the slowing down of the speed more than sending all of the chunks in one go. However, if I send all of the chunks in one go, other RPCs can't reach the receiver on time because of the RPC queue.

    So far only the disconnect and reconnect manages to get the speed back on track. I use Network.RemoveRPCs() on player disconnect - maybe that's the key. Maybe after each received file, I should remove the RPCs for that player.

    I'll keep you guys updated on this. Hopefully I'll manage to fix it because it's going to be a bummer to see the game fail because of slow file transfer.
     
  3. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    Alright, so RemoveRPCs doesn't seem to fix anything. I managed to shorten the bandwidth by making the receiver send less information about the sending progress and I made the sender send a big chunk of information about the file first and then just send the byte chunks with an id. However, this problem still occurs. Not on the server but on the clients. When clients send files to the server, the speed is always the same, however, when the server sends to the clients, the speed starts to slow down.

    I guess that is a bug in Unity and we'll release the game like that and hope that some day they'll fix it. Sorry guys for not being able to find a solution (an alternative would be to use .NET sockets and open another connection) within Unity.
     
  4. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    I have some news on the problem. I think that the jamming happens because the sender exceeds the receiver's bandwidth per second or something. Meaning that the sender tries to send more data than the receiver can handle. I did some tests and all of them seem to prove this theory.

    The only thing left is to find out a way to get each client's bandwidth (not ping) and configure the chunk sizes and amounts according to that.

    Does anybody happen to know how to perform such a check ? I couldn't find anything in Unity's API that would help me do that. I can always make it so each client sets their bandwidth but most players wouldn't even know what this is so this is not a good decision.