Unitech / Unitech/pm2

pm2 not factoring in CPU% starting using multiprocessing in python

Open
#4,921 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

pm2 is not factoring in CPU% started using multiprocessing in python it only reports <100%, however when i do "top" i see 4 python processes with 100%, thus it seems it is not recording the processes starting using multiprocessing

How could we reproduce this issue?

from multiprocessing import Pool
from multiprocessing import cpu_count
from threading import Thread, Event
from functools import partial
import signal
import time

stop = Event()

def exit_chld(x, y):
    stop.set()

signal.signal(signal.SIGINT, exit_chld)

def f(seconds, ram, x):

    def exit_after_sleep():
        time.sleep(seconds)
        stop.set()

    Thread(target=exit_after_sleep).start()

    # stress RAM (Gb)
    a = 'c' * int(ram * 1024 * 1024 * 1024)

    # stress CPU
    while not stop.is_set():
        x*x


def stress(cpus, seconds, ram_gb):
    processes = cpu_count()
    print('----------------------------------')
    print('Running load on CPU(s)')
    print(f'Utilizing {cpus}/{processes} cores')
    print(f'Take up {ram_gb/cpus} GB RAM for each process')
    print('----------------------------------')
    pool = Pool(cpus)
    pool.map(partial(f, seconds, ram_gb/cpus), range(cpus))

if __name__ == "__main__":
    stress(4, 10, 2)

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Tue Nov 17 2020 13:57:50 GMT+0800 (Singapore Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.4.0
node version         : 14.4.0
node path            : /usr/local/bin/pm2
argv                 : /usr/local/bin/node,/usr/local/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : undefined
uid                  : 1000
gid                  : 1000
uptime               : 11min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.4.0
node version         : 14.4.0
node path            : /usr/local/bin/pm2
argv                 : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0                : node
user                 : undefined
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i7-6800K CPU @ 3.40GHz
cpus nb              : 12
freemem              : 29976203264
totalmem             : 134935105536
home                 : /home/node
===============================================================================

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is identified in the issue. Start by running the supplied multiprocessing Python script under PM2 and compare its CPU report with top; done means PM2 reports CPU usage from the worker processes consistently with the system process view.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, python
Domain
cli, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.