# High use CPU - up 100%

**URL:** <https://openvidu.discourse.group/t/high-use-cpu-up-100/988>\
**Category:** Issues developing apps\
**Tags:** v2\
**Created:** [May 26, 2020, 7:39pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988 "2020-05-26T19:39:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [May 26, 2020, 7:39pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/1 "2020-05-26T19:39:10Z")

</div>

i am doing some load tests and i had some problems with CPU consumption. The kurento-media-server is consuming 100% of cpu.  
I’m testing 1: N with approximately 200 subscribers. I’m using openvidu default configurations. Only change default ports(4443-8888).  
The publisher is using ManyCam to load a virtiualCam on browser (Chrome or Firefox)  
Server:  
AMD Ryzen 5 3600 Hexa-Core  
64GB ram

Here the part of KMS log:

> 117:16:08.243382080 1 0x7fa8800af230 INFO agnosticbin kmsagnosticbin.c:774:kms\_agnostic\_bin2\_link\_pad: Upstream provided caps: audio/x-opus, rate=(int)48000, channels=(int)2, channel-mapping-family=(int)0, stream-count=(int)1, coupled-count=(int)1, streamheader=(buffer)\< 4f707573486561640102000080bb0000000000, 4f707573546167731f0000004753747265616d657220656e636f64656420766f72626973636f6d6d656e740000000001 \>  
> 117:16:08.243476528 1 0x7fa8800af230 INFO agnosticbin kmsagnosticbin.c:783:kms\_agnostic\_bin2\_link\_pad: Downstream wanted caps: audio/x-opus, channels=(int)[1, 2], channel-mapping-family=(int)0  
> 117:16:08.243760842 1 0x7fa8800af230 INFO kmsutils kmsutils.c:494:kms\_utils\_pad\_monitor\_gaps:\<‘’:sink\_video\_default\> Add probe: Detect stream gaps  
> 117:16:08.243900094 1 0x7fa8800af230 INFO agnosticbin kmsagnosticbin.c:774:kms\_agnostic\_bin2\_link\_pad: Upstream provided caps: ANY  
> 117:16:08.243916154 1 0x7fa8800af230 INFO agnosticbin kmsagnosticbin.c:783:kms\_agnostic\_bin2\_link\_pad: Downstream wanted caps: video/x-vp8  
> 117:16:08.244669801 1 0x7fa8800af230 INFO agnosticbin kmsagnosticbin.c:774:kms\_agnostic\_bin2\_link\_pad: Upstream provided caps: video/x-vp8, framerate=(fraction)23/1, height=(int)360, width=(int)480, profile=(string)0  
> 117:16:08.244697653 1 0x7fa8800af230 INFO agnosticbin kmsagnosticbin.c:783:kms\_agnostic\_bin2\_link\_pad: Downstream wanted caps: video/x-vp8  
> 117:16:08.245130226 1 0x7fa8800af230 INFO agnosticbin kmsagnosticbin.c:774:kms\_agnostic\_bin2\_link\_pad: Upstream provided caps: video/x-vp8, framerate=(fraction)23/1, height=(int)360, width=(int)480, profile=(string)0

Here, the JS of publisher:

> var publisher = OV.initPublisher(“publisher”,  
> {  
> audioSource: undefined, // The source of audio. If undefined default microphone  
> videoSource: videoSource, // The source of video. If undefined default webcam  
> publishAudio: true, // Whether you want to start publishing with your audio unmuted or not  
> publishVideo: true, // Whether you want to start publishing with your video enabled or not  
> resolution: ‘640x480’, // The resolution of your video  
> //frameRate: 30, // The frame rate of your video  
> insertMode: ‘APPEND’, // How the video is inserted in the target element ‘video-container’  
> mirror: false // Whether to mirror your local video or not  
> });

Is it a problem in the conversion?  
Thks a lot!  
Doug

---

<div class="post-metadata">

**Author:** ![micael.gallego](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/micael.gallego/32/2_2.png) [@micael.gallego](https://openvidu.discourse.group/u/micael.gallego)\
**Post date:** [May 26, 2020, 8:25pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/2 "2020-05-26T20:25:42Z")

</div>

Hello Doug,

I suppose you know the load test we do some time ago and we published here:

> **[OpenVidu load testing: a systematic study of OpenVidu platform performance](https://medium.com/@openvidu/openvidu-load-testing-a-systematic-study-of-openvidu-platform-performance-b1aa3c475ba9)**
>
> OpenVidu has evolved a lot since its inception nearly two years ago. The team has been really focused on building the core features for…

As you can see, KMS can consume a lot of CPU.

But maybe you experienced some bug we recently fixed about hight CPU consumption when tens of participants are disconnected at the same time:

> <https://github.com/Kurento/bugtracker/issues/462>
>
> Prerequisites
> 
> I have read the SUPPORT document
> 
> I have checked the Troubleshooting Guide
> 
> I have tested with the latest version of...

We have published a beta version of KMS to test with. Can you please test with this KMS version?

Also, can you share with us your load testing results?

Regards

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [May 26, 2020, 9:18pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/3 "2020-05-26T21:18:07Z")

</div>

Hi Micael! Thks for feedback!  
Oh yes, i read both topics, but as the topology is 1: N and the processing was increasing as new students entered, i thought there would be no relationship.  
I will do the update and tomorrow I can perform a new test, and return here with the result.  
Thanks again!

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [May 28, 2020, 1:38pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/4 "2020-05-28T13:38:04Z")

</div>

Hi Macael! Sorry man, i made a mistake in checking consumption.  
Im using top and forgot that it sum the percentages of all my cores. I realized this when install Htop. Excuse me again.  
So, for future reference:

> Processor: AMD Ryzen 5 3600 Hexa-Core (dedicated server)  
> Memory: 64Gb
> 
> Test 1:N: 1-230 (only one session)  
> Memory usage: ~3GB  
> Cpu usage: ~12%

As soon as possible i’m will try a massive test to see my server limit.

ps.: i’m updated the kurento suggested by j1elo and the performance stayed the same.

Thks again!  
Doug

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [June 3, 2020, 8:55pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/5 "2020-06-03T20:55:36Z")

</div>

Hi Micael! New test! Now up to 500 (1:N).  
I did a test with 3 sessions and another with only 1 session.  
In both, the connection limit was approximately 520. After that, the api returns error 500 (GET api/sessions) and no user can connect. Without doing anything, once the number of connections drops, other users are able to connect. Perhaps, a memory limitation on the JVM? I’ll look at the logs carefully to see if I can find anything.

```
Processor: AMD Ryzen 5 3600 Hexa-Core (dedicated server)
Memory: 64Gb

Test 2(1:N): 1-520 (only one session)
Memory usage: ~4GB
Cpu usage: ~40%

Test 3(1:N): 3 sessions and 520 connections
Memory usage: ~4GB
Cpu usage: ~40%

```

Thks Micael!  
Doug

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [June 4, 2020, 6:46pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/6 "2020-06-04T18:46:34Z")

</div>

Hi again my friend! I found the problem. There is a limitation on workers in nginx when try to access the API. Lets you can see:

> [alert] 71#71: 1024 worker\_connections are not enough  
> [alert] 71#71: \*6918 1024 worker\_connections are not enough while connecting to upstream

There is a way to change this config file to increase this number?  
Thks!  
Doug

---

<div class="post-metadata">

**Author:** ![micael.gallego](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/micael.gallego/32/2_2.png) [@micael.gallego](https://openvidu.discourse.group/u/micael.gallego)\
**Post date:** [June 4, 2020, 7:20pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/7 "2020-06-04T19:20:18Z")

</div>

Hello @doug,

As every user is connected with a websocket connection, then nginx has to manage all of them.

We don’t know how to increase the limits. Possibly it can be increased tweaking the nginx config.

Please share with us if you find it.

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [June 4, 2020, 7:41pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/8 "2020-06-04T19:41:02Z")

</div>

Hi Micael! Yep its simple. But the nginx.conf is inside of container image and its doesnt have a volume to map on docker-compose.yml. Im try to keep the files original as possible to not lose hard modifications when update openvidu. Is it possible take this options in a next release? Until that i will made my own modifications.  
Thks again!

---

<div class="post-metadata">

**Author:** ![micael.gallego](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/micael.gallego/32/2_2.png) [@micael.gallego](https://openvidu.discourse.group/u/micael.gallego)\
**Post date:** [June 6, 2020, 1:22am UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/9 "2020-06-06T01:22:17Z")

</div>

I think it is better if you create your own Nginx container based on the provided one.

If you fix the problem, we can include the fix in the next version.

Regards

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [June 8, 2020, 12:44pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/10 "2020-06-08T12:44:31Z")

</div>

Hi Micael! I made a copy of nginx.conf from container and create a volume in docker-compose.yml to map this file in host machine. This is more simple to edit if i need increase this number again.  
The default value in file is 1024. But, nginx used as a reverse proxy consume 2 connections per time. Running like a charm.  
Thks a lot!  
Doug

---

<div class="post-metadata">

**Author:** ![Wesley\_Swanepoel](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/wesley_swanepoel/32/474_2.png) [@Wesley\_Swanepoel](https://openvidu.discourse.group/u/Wesley_Swanepoel)\
**Post date:** [October 13, 2020, 8:04am UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/11 "2020-10-13T08:04:42Z")

</div>

@doug Any chance you can share how you went about doing this? I need to add a redirect and have no idea how to go about doing this with docker.

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [October 16, 2020, 2:51pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/12 "2020-10-16T14:51:11Z")

</div>

Hi @Wesley_Swanepoel!  
What do you mean with “redirect”?  
To increase a number of connections to your OV media server is in my last post.

---

<div class="post-metadata">

**Author:** ![Wesley\_Swanepoel](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/wesley_swanepoel/32/474_2.png) [@Wesley\_Swanepoel](https://openvidu.discourse.group/u/Wesley_Swanepoel)\
**Post date:** [October 16, 2020, 3:04pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/13 "2020-10-16T15:04:15Z")

</div>

Hi @doug. No I required a simple redirect from Nginx from www to non-www and didn’t know how to accomplish this using docker-compose but it will be sorted in the next release so no need for your example. I had an SSL issue as raised [here](https://openvidu.discourse.group/t/letsencrypt-support-for-multiple-domains-using-domain-or-public-ip/1100/4).  
Thanks  
Wes

---

<div class="post-metadata">

**Author:** ![doug](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/doug/32/260_2.png) [@doug](https://openvidu.discourse.group/u/doug)\
**Post date:** [October 16, 2020, 3:23pm UTC](https://openvidu.discourse.group/t/high-use-cpu-up-100/988/14 "2020-10-16T15:23:49Z")

</div>

Great @Wesley_Swanepoel!!
