How to reduce bandwidth consumption?

Options
Hello, I am new here!

I am creating a multiplayer game. Because of the limits of 500Msg/s per room I have limited the size of the room to 6 players.

Every player update their position 7 times per second broadcasting to the rest of the room. That gives about 250Mgs/s per room. Below the limits, what is cool.

The problem here is that I am seeing that the bandwidth is about 14KB/s per room of 6 players. Photon estimates 3GB per CCU every month.

So doing the maths we have:

14KB *3600s*24h*30d = 34GB per month

3GB * 6 players in a room = 18GB per month

So 34 >>>>18.

I understand that not every room will be full every second of the month and that I wont have just 20CCU all the time. I would have to upgrade the plan if that was the case. But the thing is that what I currently have in my game is so basic that I don't see how can I make this numbers fit.

Every player has his photonview and for every photonView I am just sending position and velocity:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
            if (stream.IsWriting) {
                stream.SendNext(this.rigidBody.position);
                stream.SendNext(this.rigidBody.velocity);
            } else {
                networkPosition = (Vector2)stream.ReceiveNext();
                rigidBody.velocity = (Vector2)stream.ReceiveNext();

                float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.SentServerTime));
                 
                networkPosition += (this.rigidBody.velocity * lag);

                speed = (rigidBody.position - networkPosition).magnitude;
            }
        }   

As I said, the serialization rate is even lower than the default value:
PhotonNetwork.SendRate = 14;
PhotonNetwork.SerializationRate = 7;

Should I do some configuration to make my messages smaller? PUN support up to 16 players in a room. How do they handle? Because with only 6 things scalates pretty quickly.

Also, just dividing 14KB/s / 250Msg/s gives about 57B/Msg. So messages are not so big, just 57Bytes wtih all the headers and stuff.

I don't know if the only viable option is just to make clients send to master and master broadcast to the rest. Is there a way to do that with photonView or would I have to do it manually? I would like to avoid that option because it brings more lag talking client to client.

Thanks!

Best Answer

Answers

  • Cebado
    Cebado
    edited October 2020
    Options
    Since the players wont be runing faster than 327 I can use two shorts to send the velocity instead of a Vector2. That would save me 4 bytes every call and now a room with 6 players use less than 12KB/s.
    //Send
    short speedX = (short)(this.rigidBody.velocity.x * 100f);
    short speedY = (short)(this.rigidBody.velocity.y * 100f);
    stream.SendNext(speedX);
    stream.SendNext(speedY);
    
    //...........
    
    //Receive
    rigidBody.velocity = new Vector2(((short)stream.ReceiveNext()) / 100f, ((short)stream.ReceiveNext()) / 100f);
    

    I think that I wont have problems because its impossible to have all the time all CCU and all rooms with max players, but anyway I would like to reduce it even more.
  • Cebado
    Options

    Thank you very much. The compression approach is more or less what I did for the velocity I think. I will try it also for the vector3.

    And I will read that photon documentation carefully. I was searching something like that and I couldn't find it by my own.