question

Derek DeCramer avatar image
Derek DeCramer asked

how to reduce lag

Hello, I am making a multiplayer game using Unity, mirror networking with kcp transport, and playfab. I recently uploaded a server build with a healthy status and clients are able to connect to the server just fine, although it takes about 10 seconds. Attempting to move the player object on the client can take up to 10 seconds before a response is seen. Also, other network objects are incredibly laggy. I am currently using the free playfab services and am only testing with 1 server active at a time.

When I host the game locally on my own pc, there is no lag at all.

What are the first things I should look to change to reduce this lag and make the game playable? I don't want to waste too much time waiting for different server builds to deploy.

,

I made a multiplayer game on unity and I recently uploaded my server build to playfab and it has a healthy status. Clients are able to connect fine to the server, although it does take about 10 seconds. When I host the server locally on my own computer, there is no lag at all. On playfab however, networked objects are extremely laggy, and using cmd and rpc functions in order to communicate between client and server take about 10 seconds in total before and response is seen on the client. I am using mirror networking with kcp transport.

What are the first things I should look to change to reduce lag and make the game playable?

I don't want to waste too much time waiting for server builds to deploy.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

If the region of your clients is too far away from the region you deployed the server on, it may cause a high-latency connections. In this case, the movement you want to synchronize will have a high lag. To order to obtain a low-latency connection, you need to ensure the Quality-of-Service (QoS) of the servers is sufficient to support your gameplay.

We would suggest you evaluate the QoS of different Azure regions to determine which has the lowest latency. You can refer to our documentation -- Quality-of-service (QoS) beacons to measure player latency to Azure, specially this section Using the quality-of-service SDK to learn about how to evaluate the QoS using the QoS beacons PlayFab operates in every Azure region that used by PlayFab multiplayer servers.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Derek DeCramer avatar image Derek DeCramer commented ·

I have changed the region to Central US which is where I am from. The server build is run using a linux container on an Av2 (1 core) virtual machine. If I use any more than 1 server per machine, the in game ping is above 1000. If I only use 1 server per machine however, the in game ping is around 100 which is honestly very acceptable for my simple multiplayer mobile real-time game. I am currently using the free 'pay as you go' plan, and the price of 1 server per machine for a 4 person game is too high for me.

The ping typically spikes to 1000+ when the unity scene changes from the lobby scene to the game scene, but only with more than 1 server per machine.

Things I have tried to fix this issue include reducing the amount of network objects in my scene, reducing the movement of some of the network objects on the server so it has less calculations to do, and reducing the amount of times cmd functions are called.

I could try merging the ingame scene with the lobby scene but that seems like a worsely-organized game design. Do scene changes normally spike ping in games?

Do you have any suggestions on how I can increase servers per machine without the ping increasing drastically?

Thanks.

0 Likes 0 ·
Greg Quinn avatar image Greg Quinn Derek DeCramer commented ·

Have you run a test to see how much CPU and RAM a game server instance is using?


Scene loading is usually a blocking operation, are you using https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html ?

I'm guessing one server instance of your game is too much for the one core cpu to handle, and thus when you are running two server instances, it just can't serve the game smoothly, hence the high pings. I would suggest trying a more powerful server.

Also, try turning off any cameras in your server build, and make sure you are running it as headless. (Server build in Unity settings)

Also, your game server instance shouldn't have any assets, just the lean, core logic and meshes for any physics.

1 Like 1 ·
Derek DeCramer avatar image Derek DeCramer Greg Quinn commented ·

I tested the cpu and ram locally. I wasn't sure how to test it on playfab, but I noticed that on the playfab vm metrics cpu usage user is at nearly 100% which seems like a bad thing. These stats are after turning off all cameras, as well as other unnecessary gameobjects. I also tried switching everything to one scene, and that turned out to not be the issue, the real issue being simply when the gameplay begins. And I was already running it as headless.

I will post another reply to attach another file.

0 Likes 0 ·
processinfo.png (28.1 KiB)
dockerstats.png (3.7 KiB)
Show more comments
Greg Quinn avatar image Greg Quinn Derek DeCramer commented ·

By assets I mean artwork, textures, sounds, etc, anything that would be seen or heard in the game doesn't need to be on the server.

Your scene would literally have the scripts to the run the scene/game logic, and if you have physics, just the meshes/models that are required for physics calculations.

For the server/lag issues just try running a higher server spec.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.