Passthrought CPU usage

Post here to ask any questions about hardware suitability, configuration in ZoneMinder, or experiences. If you just want to know if something works with ZoneMinder or not, please check the Hardware Compatibility sections in the forum, and the Wiki first. Also search this topic as well.
Post Reply
milosd
Posts: 3
Joined: Fri Aug 07, 2020 6:38 am

Passthrought CPU usage

Post by milosd »

Hi, I have installed zoneminder on dedicated machine to test zoneminder for future use and I think the CPU usage is not reasonable - Load around 0.9-1.2 for passthrough H264 (zmc -m4 shows 33-39% cpu% which does not relate directly with load. Interesting is that if Space calculation filter runs, ZMC -m4 cpu% drops to around 9%). Please help me understand it.
I have Single camera in use Hikvision DS-2DE4215IW-DE. Zoneminder is capturing both streams in Record mode to eliminate analysis from equation.
I suspect it is ZM is converting captured stream somehow. I have tried change resolution, color depth and camera setting in many combinations but did not get to better system load.

ltrace shows following - is it correct for correct passthrough without decoding (personally i do not like sws_scale there?

Code: Select all

ltrace -c -p 3085
^C% time     seconds  usecs/call     calls      function
------ ----------- ----------- --------- --------------------
 60.76    3.882682       39219        99 av_read_frame
 18.70    1.194938       12070        99 avcodec_send_packet
 13.58    0.867789        8677       100 sws_scale
  0.80    0.051082         127       400 __snprintf_chk
  0.79    0.050795         128       396 av_rescale_q
  0.70    0.044412         111       400 gettimeofday
  0.69    0.043794       21897         2 mysql_query
  0.52    0.033255         111       298 av_init_packet
  0.48    0.030527         102       299 av_packet_unref
  0.39    0.024730         124       198 _Znwm
  0.31    0.019896         198       100 avcodec_receive_frame
  0.28    0.018106         179       101 localtime
  0.24    0.015609         156       100 av_image_fill_arrays
  0.24    0.015216         153        99 av_interleaved_write_frame
  0.19    0.012287         124        99 av_packet_ref
  0.18    0.011686         118        99 _ZNSt8__detail15_List_node_base7_M_hookEPS0_
  0.18    0.011329         114        99 av_packet_rescale_ts

zmc log - open ocures every 10 minutes

Code: Select all

08/07/20 08:47:14.401690 zmc_m4[3085].INF-zm_ffmpeg_camera.cpp/802 [Re-starting video storage module]
08/07/20 08:47:14.476194 zmc_m4[3085].INF-zm_videostore.cpp/62 [Opening video storage stream /kamery/zaznam/dvur/detail/4/2020-08-07/14436/14436-video.mp4 format: mp4]
08/07/20 08:47:14.595082 zmc_m4[3085].INF-zm_ffmpeg_camera.cpp/879 [Event video offset is -2.757 sec (<0 means video starts early)]
08/07/20 08:47:15.626286 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:35900 - Capturing at 14.29 fps, capturing bandwidth 204962bytes/sec]
08/07/20 08:47:22.294145 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36000 - Capturing at 14.29 fps, capturing bandwidth 194772bytes/sec]
08/07/20 08:47:28.965121 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36100 - Capturing at 16.67 fps, capturing bandwidth 225162bytes/sec]
08/07/20 08:47:35.612424 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36200 - Capturing at 14.29 fps, capturing bandwidth 191892bytes/sec]
08/07/20 08:47:42.294631 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36300 - Capturing at 14.29 fps, capturing bandwidth 191893bytes/sec]
08/07/20 08:47:48.947898 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36400 - Capturing at 16.67 fps, capturing bandwidth 219900bytes/sec]
08/07/20 08:47:55.608066 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36500 - Capturing at 14.29 fps, capturing bandwidth 195589bytes/sec]
08/07/20 08:48:02.296030 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36600 - Capturing at 14.29 fps, capturing bandwidth 198905bytes/sec]
08/07/20 08:48:08.966793 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36700 - Capturing at 16.67 fps, capturing bandwidth 241063bytes/sec]
08/07/20 08:48:15.626762 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36800 - Capturing at 14.29 fps, capturing bandwidth 202781bytes/sec]
08/07/20 08:48:22.295703 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:36900 - Capturing at 14.29 fps, capturing bandwidth 190577bytes/sec]
08/07/20 08:48:28.967716 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37000 - Capturing at 16.67 fps, capturing bandwidth 235123bytes/sec]
08/07/20 08:48:35.628201 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37100 - Capturing at 14.29 fps, capturing bandwidth 232794bytes/sec]
08/07/20 08:48:42.296722 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37200 - Capturing at 14.29 fps, capturing bandwidth 208902bytes/sec]
08/07/20 08:48:48.966803 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37300 - Capturing at 16.67 fps, capturing bandwidth 233905bytes/sec]
08/07/20 08:48:55.634220 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37400 - Capturing at 14.29 fps, capturing bandwidth 226117bytes/sec]
08/07/20 08:49:02.278086 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37500 - Capturing at 14.29 fps, capturing bandwidth 201218bytes/sec]
08/07/20 08:49:08.968908 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37600 - Capturing at 16.67 fps, capturing bandwidth 242881bytes/sec]
08/07/20 08:49:15.631194 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37700 - Capturing at 14.29 fps, capturing bandwidth 216325bytes/sec]
08/07/20 08:49:22.297758 zmc_m4[3085].INF-zm_monitor.cpp/2544 [Dvur-HiRes: images:37800 - Capturing at 14.29 fps, capturing bandwidth 204965bytes/sec]
...

Configuration of camera main stream

Code: Select all

Resolution 1920x1080P
FPS: 15
Coding H.264
H.264+ OFF
Zoneminder configuration

Code: Select all

SourceType: Ffmpeg
function: Record
MaxFps, etc - Blank regarding to several forum posts

Source
rtsp://*/Streaming/Channels/1/
Target colorspace: 32bit
resolution: 1920x1080
deinterlacing: Disabled
Image Buffer Size: 400 (increased after complains in log)

System HW (crap what was available at the moment)
Intel(R) Pentium(R) Gold G5400 CPU @ 3.70GHz
16G Ram
Storage ZFS 2disk mirror without significant load
SteveGilvarry
Posts: 494
Joined: Sun Jun 29, 2014 1:12 pm
Location: Melbourne, AU

Re: Passthrought CPU usage

Post by SteveGilvarry »

It is decoding for the live view.
Production Zoneminder 1.37.x (Living dangerously)
Random Selection of Cameras (Dahua and Hikvision)
milosd
Posts: 3
Joined: Fri Aug 07, 2020 6:38 am

Re: Passthrought CPU usage

Post by milosd »

I see, thanks for fast reply. And is there a way to switch this functionality off? It will stress CPU for no reason most of the time. My uscase needs only recording and history review. I came across one bash script for external recording and registring data to ZM database but that is too hacky with possible future problems.

Aside from ZM, are you able to explain drop of CPU% when zm filter is running? It looks like it is showing cpu share of all running processes.

Only recording 2 streams from one camera

Code: Select all

Tasks: 336 total,   3 running, 333 sleeping,   0 stopped,   0 zombie
%Cpu(s): 14.9 us,  2.7 sy,  0.0 ni, 82.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15935.8 total,   3149.3 free,   8182.6 used,   4603.9 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   4027.4 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 3085 www-data  20   0 3491084   3.1g   3.1g R  31.2  20.2  69:57.81 zmc
13661 www-data  20   0  296336 107760  93484 R  12.5   0.7  27:52.73 zmc
Filter active

Code: Select all

Tasks: 336 total,   2 running, 334 sleeping,   0 stopped,   0 zombie
%Cpu(s): 17.1 us, 11.6 sy,  0.0 ni, 65.7 id,  4.9 wa,  0.0 hi,  0.7 si,  0.0 st
MiB Mem :  15935.8 total,   3115.2 free,   8214.7 used,   4605.9 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   3995.3 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
14659 www-data  20   0   58560  44668   8008 R  99.3   0.3  84:51.01 zmfilter.pl
 3085 www-data  20   0 3491084   3.1g   3.1g S   8.0  20.2  70:25.46 zmc
13661 www-data  20   0  296336 107760  93484 S   4.3   0.7  28:03.64 zmc

milosd
Posts: 3
Joined: Fri Aug 07, 2020 6:38 am

Re: Passthrought CPU usage

Post by milosd »

I am still unsure if it needs to spend so much CPU time in *scale functions so i dug deeper so I'm sending more details - detail on stream

Code: Select all

 ffprobe rtsp://record:************@172.16.240.66:554/Streaming/Channels/1/ -v error -show_format -show_streams
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=Main
codec_type=video
codec_time_base=1/30
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
width=1920
height=1080
coded_width=1920
coded_height=1088
has_b_frames=0
sample_aspect_ratio=N/A
display_aspect_ratio=N/A
pix_fmt=yuvj420p
level=42
color_range=pc
color_space=bt709
color_transfer=bt709
color_primaries=bt709
chroma_location=left
field_order=progressive
timecode=N/A
refs=1
is_avc=false
nal_length_size=0
id=N/A
r_frame_rate=15/1
avg_frame_rate=15/1
time_base=1/90000
start_pts=36030
start_time=0.400333
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]
[FORMAT]
filename=rtsp://record:************@172.16.240.66:554/Streaming/Channels/1/
nb_streams=1
nb_programs=0
format_name=rtsp
format_long_name=RTSP input
start_time=0.400333
duration=N/A
size=N/A
bit_rate=N/A
probe_score=100
TAG:title=Media Presentation
[/FORMAT]
SteveGilvarry
Posts: 494
Joined: Sun Jun 29, 2014 1:12 pm
Location: Melbourne, AU

Re: Passthrought CPU usage

Post by SteveGilvarry »

No way to turn it off at the moment, it is on my own wish list. But I do still want live view, but I don't need to decode for it.

Not sure why the cpu% is doing that, at first I was thinking the filter is taking it all so the others were dropping down. I will have a look at mine see if I see the same.
Production Zoneminder 1.37.x (Living dangerously)
Random Selection of Cameras (Dahua and Hikvision)
Post Reply