The video is lagging

Hello, I’m new to mediasoup and I’ve recently developed a conference meeting application. During my initial deployment, the video functionality was working perfectly. However, after I deployed an update with new features, I noticed that the video started lagging. I tried reverting my code back to its state before the first deployment to know whats the problem, but the lagging issue persists. By the way, I want to express my appreciation for the wonderful library that is mediasoup – it has been truly awesome.
Here is my prototype : https://modotz.net
Thank you.

The link isn’t working

Can you show me the errors message?
Maybe something like nginx page or error in console.

I’m quite unfamiliar with this situation. I attempted to use the IP address, and it seems to be functioning correctly. I’m unable to identify the root of the issue. What I can share is that while troubleshooting the lagging problem in my project, I noticed instability in the producer connection during the production phase. The connection status appeared to cycle through ‘connecting,’ ‘connected,’ and 'failed.

The poor connection can definitely be a problem in that case.

Another thing to check is whether you are using UDP or TCP. UDP is more preferred, TCP can create lags.

A poor connection is unlikely to be the issue, as I’ve tested it on various networks. I configured my code to enable both UDP and TCP, although UDP is the preferred protocol.

Here’s the scenario: my initial project deployment worked seems fine . However, after I made changes during the subsequent deployment, I encountered video lagging. Consequently, I chose to revert my code to the state of the initial deployment, but the lagging persisted. This has led me to question whether the problem might be related to my VPS.

Currently, I’m utilizing only one worker and one router. I’m wondering if this is the appropriate approach for a conference setup, or if there might be a more effective method?

If you haven’t changed mediasoup version and just changed your logic then this can be some issue in the code like configuration etc. Check with the configuration like bitrate etc you provided.

One worker is not enough, each worker have limitation based upon the CPU. Using one worker in production is not good. You should use multiple workers divide your call between them and using piping to connect between routers of different workers. Check the piping mechanism described in documentation.

But as you said you are just testing so at this point one worker shouldn’t be causing the lag.
Also check the network conditions on your server.

Go to chrome://webrtc-internals in chrome browser and you can see from there how much bits/seconds are yous sending and receiving on the transport/peer connection. It should give you idea.

Also make sure you are not capturing video with low FPS. If local video is playing smoothly then this is not the issue.

I set up separate workers for each distinct room in a different development code. I was under the impression that utilizing a single router would be sufficient and that there was no requirement for using piping to establish connections between routers. This was based on my use of a single router for each worker. It seems I my method is wrong?
Btw, thanks for the advice

Following your suggestion, I monitored the situation and gathered data from chrome://webrtc-internals. The data clearly indicates a significant amount of packet loss. Would it be reasonable to assume that there is a network problem or limitations on my VPS?
ConnectionState 2


It is not ideal to open more workers than number cores in CPU. You can but it can lead to race condition between processes. So instead of using one worker for one room. You should try to adjust multiple rooms in a worker until it is reaching it’s capacity, then open new worker and utilise that, keep doing that until the CPU is about reach it’s capacity. There will be scenarios where one room is on more than one workers and in that case you will have to use piping at all costs otherwise you will not be able to share streams between the workers. After one machine is full, you will need another machine and so on, and use piping between workers on different machines to achieve the target.

Using one router in one worker is not an issue. Router have not limits, worker have.

This is the basic structure which we should follow. It all depends on your needs, requirements.

The bytes received in bits/s are quite low. Not good for a video call. You should see how many bytes are being sent, if they are being sent in low amount then that is the issue, you will have to look into why they being sent in that low amount.

Also you need to verify the maxBitrate thing if you have provided to produce() method. I use them to keep the video bitrate limited to avoid excessive bandwidth usage.

Thank you, this answer has answered many questions I had.

I’ve set the options with three layers: 100000, 300000, and 900000. Despite this, I’m still experiencing lagging issues. Here’s a graphical representation of how many bytes are being sent. Even though I’ve set the maxBitrate values to 100000, 300000, and 900000, the problem persists.

The bitrate went up to 1.5M and then it came down to 0, I guess because of the disconnection it is facing. Does this same happens when you run the server locally and test?

There may be issue with the server which is making the connection close so frequently, or may be something in the code that does that.

Try running mediasoup demo on server and see if you face the same issue.

Also try removing this altogether just to test.

Check with the server as well, whether if is overloading or not.

I just tried your application and the bytes sent are constant at 100 kb/s, which is one of the bitrate options you have specified and this seems to be the reason. You might be forcing somewhere. So remove this altogether these 3 layers and then try, it should be all good.

Indeed, I noticed that the bytes sent are consistently at 100 kb/s when using a VPS. When testing locally with encoding set to 100000, 300000, and 900000, the bytes sent fluctuate between 500 kb/s and 1500 kb/s. Additionally, when testing locally without encoding, the bytes sent range between 500 kb/s and 1750 kb/s. I’ve recorded a video demonstrating these results. I’m uncertain about the discrepancy in bytes being sent between the local and cloud server setups with the same encoding options.

Try checking with your server, whether there is some restriction there. Check the usage when call is running all that stuff. And change max bitrate from 100000, 300000, and 900000 to 500000, 700000, 900000. Just to make sure if it is not problem.

I followed your suggestions, but the issue of lagging persists. Due to this, I suspect that there might be a problem with the cloud server. Additionally, I’ve noticed that the consumer state changes from connected to failed/closed and then back to connected. Could this be attributed to a lack of received bytes, or is there another reason for this behavior?

You must check with the server, and also try running mediasoup demo on the same server to make sure there is nothing in your code.