Search Unity

Controlling Traffic Flow (no free events for message)

Discussion in 'Multiplayer' started by Jmangles, Jun 11, 2017.

  1. Jmangles

    Jmangles

    Joined:
    Aug 1, 2015
    Posts:
    53
    I'm having a lot of problems with the "no free events for message in the pool" and "no free events for long message in the pool" errors followed by client disconnects.

    I literally cannot seem to get Unity to allow for my game to function even with the most extreme network settings such as :

    Code (csharp):
    1.         connectionConfig.AcksType = ConnectionAcksType.Acks128;
    2.         connectionConfig.MaxSentMessageQueueSize = 2048;
    3.         connectionConfig.FragmentSize = 1000;
    4.         connectionConfig.MaxCombinedReliableMessageCount = 128;
    5.         connectionConfig.MaxCombinedReliableMessageSize = 100;
    6.         connectionConfig.PacketSize = 1470;
    Along with that I set every single channel to have 500 pending buffers in OnServerConnect.

    I can have hundreds of things occur per second that players need to have sent to them, so if this is not going to work out in its current state, I'm wondering how a flow controller is supposed to be set up so I can aggregate all of my tiny packets. My NoResources errors that show up after the no free events messages are all for transfers as tiny as 7 bytes.

    If anyone can shed some light onto this sort of issue and how to deal with it, I'm all ears, I am quite confused.
     
  2. Jmangles

    Jmangles

    Joined:
    Aug 1, 2015
    Posts:
    53
    Since this sort of thing doesn't have enough solutions on google, I'll add this for people who end up here in the future.

    In my case I ran out of messages due to sending a ton of tiny variable updates for RPG-like characters. Before I fixed this I made it so updates to stats for players only occurred if a client was actively inspecting the character and updates came in the form of a byte header which was the ID of the variable followed by a byte array representing the variable data. This was not enough on its own to reduce the number of packets sent per second to an acceptable level.

    The fix was to make it so variable changes were not immediately sent but rather they just set the bit of a long that corresponded to their byte ID. Then in an infinitely running coroutine all the variables marked "dirty" in the long get packed together in a single byte array and sent off. Once this is done the long gets set to 0 to reset all the bits and it repeats after a set delay timer.

    This seems to have done the trick since now blowing up a group of 30 enemies with an AoE spell doesn't cause 60+ transfers for the 30 kill amount updates and 30 xp amount updates, instead now I get a single update with both of those variable's most recent values.
     
    ddsim likes this.