# Limit Obfs4 bridge CPU usage

**URL:** <https://forum.torproject.org/t/limit-obfs4-bridge-cpu-usage/11904>\
**Category:** Relay Operator\
**Created:** [March 13, 2024, 9:45pm UTC](https://forum.torproject.org/t/limit-obfs4-bridge-cpu-usage/11904 "2024-03-13T21:45:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirNeo](https://forum.torproject.org/user_avatar/forum.torproject.org/sirneo/32/1933_2.png) [@SirNeo](https://forum.torproject.org/u/SirNeo)\
**Post date:** [March 13, 2024, 9:45pm UTC](https://forum.torproject.org/t/limit-obfs4-bridge-cpu-usage/11904/1 "2024-03-13T21:45:34Z")

</div>

My best obfs4 bridge (100-150 users on the last 6months) is not working anymore because the VPS was suspended due to FUP for CPU.

Please let me know how i can limit the number of users to 80 let’s say or how to limit the process cpu usage to 50%

---

<div class="post-metadata">

**Author:** ![Throughget](https://forum.torproject.org/letter_avatar_proxy/v4/letter/t/dbc845/32.png) [@Throughget](https://forum.torproject.org/u/Throughget)\
**Post date:** [March 13, 2024, 10:31pm UTC](https://forum.torproject.org/t/limit-obfs4-bridge-cpu-usage/11904/2 "2024-03-13T22:31:57Z")

</div>

One technique I’ve used in the past when I had to limit CPU was to use the **cpulimit** utility.

As an example, I had this saved in case I needed to use it again at some point:  
`sudo cpulimit -P /usr/sbin/tor -b -c 1 -l 50 -m`

This is what I used to invoke tor and limit cpu usage to 50%. You may have to play with it a little to get it working on your system (e.g. changing the path, or percentage) but should be enough to try some things out.

Looking at the command again, not sure why I used the -m parameter as the manual seems to suggest it shouldn’t be used in most cases - but I had it there for a reason and I don’t recall why, perhaps as it was a system dedicated to running tor and I didn’t care about accidently limiting other processes? Unknown.

---

<div class="post-metadata">

**Author:** ![SirNeo](https://forum.torproject.org/user_avatar/forum.torproject.org/sirneo/32/1933_2.png) [@SirNeo](https://forum.torproject.org/u/SirNeo)\
**Post date:** [March 14, 2024, 12:12pm UTC](https://forum.torproject.org/t/limit-obfs4-bridge-cpu-usage/11904/3 "2024-03-14T12:12:27Z")

</div>

> [@Throughget](#):
>
> -P /usr/sbin/tor -b -c 1 -l 50 -m

Thanks for the advice but something goes wrong.

> root@s15280 ~ # whereis tor  
> tor: /usr/bin/tor /usr/sbin/tor /etc/tor /usr/share/tor /usr/share/man/man1/tor.1.gz

> root@s15280 ~ # sudo cpulimit -P /usr/sbin/tor -b -c 1 -l 50 -m  
> root@s15280 ~ # Warning: no target process found. Waiting for it…  
> root@s15280 ~ # sudo cpulimit -P /usr/bin/tor -b -c 1 -l 50 -m  
> root@s15280 ~ # Process 478 detected

After i run the cpulimit command a lot of cpulimit instances are starting and are abussing the CPU more than without cpulimit

 ![image](https://forum.torproject.org/uploads/default/original/2X/3/383105e290e084bb610bcc8801ba4d7a4f0649d3.png)

> root@s15280 ~ # top  
> top - 11:14:06 up 8:36, 1 user, load average: 184.13, 95.16, 40.32  
> Tasks: 426 total, 108 running, 318 sleeping, 0 stopped, 0 zombie  
> %Cpu(s): 15.4 us, 61.4 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 1.9 si, 21.3 st  
> MiB Mem : 979.0 total, 247.4 free, 695.4 used, 36.2 buff/cache  
> MiB Swap: 1024.0 total, 958.1 free, 65.9 used. 195.6 avail Mem

> ```
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 
> ```
> 
> 5481 root 9 -11 76260 128 0 D 0.9 0.0 0:01.14 cpulimit  
> 479 debian-+ 20 0 1327148 59372 0 S 0.7 5.9 50:16.56 obfs4proxy  
> 5641 root 9 -11 76260 132 0 S 0.7 0.0 0:00.39 cpulimit  
> 5426 root 9 -11 76260 380 248 S 0.6 0.0 0:01.36 cpulimit  
> 5429 root 9 -11 76260 128 0 D 0.6 0.0 0:01.34 cpulimit  
> 5431 root 9 -11 76260 128 0 D 0.6 0.0 0:01.37 cpulimit  
> 5433 root 9 -11 76260 356 224 D 0.6 0.0 0:01.30 cpulimit  
> 5435 root 9 -11 76260 128 0 D 0.6 0.0 0:01.33 cpulimit  
> 5440 root 9 -11 76260 376 244 D 0.6 0.0 0:01.32 cpulimit  
> 5444 root 9 -11 76260 128 0 D 0.6 0.0 0:01.24 cpulimit  
> 5447 root 9 -11 76260 128 0 D 0.6 0.0 0:01.25 cpulimit  
> 5448 root 9 -11 76260 368 236 D 0.6 0.0 0:01.28 cpulimit  
> 5449 root 9 -11 76260 336 204 S 0.6 0.0 0:01.28 cpulimit  
> 5451 root 9 -11 76260 368 236 D 0.6 0.0 0:01.29 cpulimit  
> 5455 root 9 -11 76260 368 236 D 0.6 0.0 0:01.22 cpulimit  
> 5456 root 9 -11 76260 128 0 D 0.6 0.0 0:01.24 cpulimit  
> 5466 root 9 -11 76260 368 236 S 0.6 0.0 0:01.17 cpulimit  
> 5468 root 9 -11 76260 372 240 D 0.6 0.0 0:01.17 cpulimit  
> 5471 root 9 -11 76260 380 248 D 0.6 0.0 0:01.20 cpulimit  
> 5472 root 9 -11 76260 368 236 S 0.6 0.0 0:01.19 cpulimit  
> 5473 root 9 -11 76260 128 0 D 0.6 0.0 0:01.19 cpulimit  
> 5474 root 9 -11 76260 376 244 D 0.6 0.0 0:01.22 cpulimit  
> 5475 root 9 -11 76260 372 244 D 0.6 0.0 0:01.17 cpulimit  
> 5479 root 9 -11 76260 376 244 S 0.6 0.0 0:01.13 cpulimit  
> 5480 root 9 -11 76260 372 240 D 0.6 0.0 0:01.13 cpulimit  
> 5484 root 9 -11 76260 356 224 D 0.6 0.0 0:01.12 cpulimit  
> 5489 root 9 -11 76260 124 0 S 0.6 0.0 0:01.08 cpulimit  
> 5509 root 9 -11 76260 372 236 S 1.0 0.0 0:01.02 cpulimit  
> 5512 root 9 -11 76260 132 0 S 1.0 0.0 0:00.98 cpulimit  
> 5513 root 9 -11 76260 372 236 S 1.0 0.0 0:00.96 cpulimit  
> 5519 root 9 -11 76260 376 240 S 1.0 0.0 0:00.92 cpulimit  
> 5530 root 9 -11 76260 380 244 S 1.0 0.0 0:00.88 cpulimit  
> 5531 root 9 -11 76260 132 0 S 1.0 0.0 0:00.88 cpulimit  
> 5540 root 9 -11 76260 360 224 S 1.0 0.0 0:00.86 cpulimit  
> 5547 root 9 -11 76260 372 236 S 1.0 0.0 0:00.78 cpulimit  
> 5555 root 9 -11 76260 376 240 S 1.0 0.0 0:00.79 cpulimit  
> 5557 root 9 -11 76260 132 0 S 1.0 0.0 0:00.75 cpulimit  
> 5565 root 9 -11 76260 380 244 S 1.0 0.0 0:00.73 cpulimit  
> 5568 root 9 -11 76260 372 236 S 1.0 0.0 0:00.77 cpulimit  
> 5573 root 9 -11 76260 376 240 S 1.0 0.0 0:00.71 cpulimit  
> 5581 root 9 -11 76260 136 0 S 1.0 0.0 0:00.64 cpulimit  
> 5589 root 9 -11 76260 372 236 S 1.0 0.0 0:00.58 cpulimit  
> 5597 root 9 -11 76260 308 172 S 1.0 0.0 0:00.57 cpulimit  
> 5611 root 9 -11 76260 136 0 S 1.0 0.0 0:00.50 cpulimit  
> 5616 root 9 -11 76260 340 204 S 1.0 0.0 0:00.50 cpulimit  
> 5625 root 9 -11 76260 372 236 S 1.0 0.0 0:00.42 cpulimit  
> 5627 root 9 -11 76260 372 236 S 1.0 0.0 0:00.38 cpulimit  
> 5633 root 9 -11 76260 372 236 S 1.0 0.0 0:00.39 cpulimit  
> 5651 root 9 -11 76260 308 172 S 1.0 0.0 0:00.30 cpulimit  
> 5653 root 9 -11 76260 136 0 S 1.0 0.0 0:00.25 cpulimit  
> 5670 root 9 -11 76260 136 0 S 1.0 0.0 0:00.16 cpulimit  
> 5671 root 9 -11 76260 136 0 S 1.0 0.0 0:00.14 cpulimit  
> 479 debian-+ 20 0 1327148 59372 0 S 0.6 5.9 50:16.51 obfs4proxy  
> 5330 root 9 -11 76260 392 256 R 0.6 0.0 0:01.69 cpulimit  
> 5333 root 9 -11 76260 392 256 R 0.6 0.0 0:01.75 cpulimit  
> 5344 root 9 -11 76260 128 0 S 0.6 0.0 0:01.70 cpulimit

---

<div class="post-metadata">

**Author:** ![Tangerine](https://forum.torproject.org/user_avatar/forum.torproject.org/tangerine/32/5184_2.png) [@Tangerine](https://forum.torproject.org/u/Tangerine)\
**Post date:** [March 18, 2024, 7:55am UTC](https://forum.torproject.org/t/limit-obfs4-bridge-cpu-usage/11904/4 "2024-03-18T07:55:35Z")

</div>

Hey SirNeo, did you fix the problem? If not I have a few ideas:

- Setting `RelayBandwidthRate` and `RelayBandwidthBurst` in the `torrc` file might reduce the CPU load in a more indirect and “natural” way by limiting how many clients are connected.

- About using `cpulimit`, maybe dropping the `-m` flag could prevent it from launching too many processes. The man page says

> “Warning: It is usually a bad idea to use this flag on a shell script. The commands in the script will each spawn a process which will, in turn, spawn more copies of this program to throttle them, bogging down the system.”

- Also curious if the `-c` flag is really needed or if it’s part of the issue. Just using `-l 50` to limit CPU usage might simplify things.

- On my own bridge there are also `obfs4proxy` processes running (/usr/bin/obfs4proxy) that might be worth watching out for too.

Hope that helps!
