Motion-Project / motion

Motion, a software motion detector. Home page: https://motion-project.github.io/
GNU General Public License v2.0
3.64k stars 547 forks source link

Script Execution causes very high CPU load #1160

Closed Whytey closed 4 years ago

Whytey commented 4 years ago
  1. Reviewed guide and contributing documents? (Yes/No): Yes
  2. version [x.y.z, hash, other]: 4.3.1
  3. installed as a package or compiled from sources [deb, rpm, git, other]: deb
  4. standalone or part of third party [motion, MotionEyeOS, other]: standalone
  5. video stream source [V4L (card or USB), net cam (mjpeg, rtsp, other), mmal]: JPEG snapshots via HTTP
  6. hardware [x86, ARM, other]: LXD container on x86
  7. operating system [16.04, Stretch, etc, FreeBSD, other]: Ubuntu

Not too sure where to start but if I have the following in my configuration on_picture_save echo %f >> /tmp/motion.capture ...when I capture at 1fps per 2 seconds, that script/command is being called but the load on the machine to spawn the new process is very high.

Normally I would run with 7 IP cams and without calling the on_picture script I have a load of ~3. If I add the script it jumps to >20 within 10-15 seconds and keeps climbing. I would expect that the on_picture script is only being called 7 times per 2 seconds in a non-motion-event situation.

I quickly wrote a python script to launch up to 600 processes per 2 seconds and there was no noticeable impact to the load, so this seems to be localised to motion.

Any thoughts??

tosiara commented 4 years ago

How do you capture at 1fps per 2 seconds? Upload your full config and a full log with -d 7

Whytey commented 4 years ago

Hi,

Sorry, capture at a max framerate of 2 fps, but snapshot_interval is 2 seconds

(so effectively the command should run once per 2 seconds per camera in a normal situation).

root@dvr:/tmp# cat /etc/motion/motion.conf | grep -v '^#' | grep -v '^$' daemon off pid_file /var/run/motion/motion.pid setup_mode off framerate 2 minimum_frame_time 0 threshold 1500 threshold_tune off noise_level 32 noise_tune on despeckle_filter EedDl smart_mask_speed 0 lightswitch_percent 50 minimum_motion_frames 2 pre_capture 5 post_capture 30 event_gap 60 movie_max_time 0 emulate_motion off picture_output on picture_output_motion off picture_quality 90 movie_output off movie_output_motion off timelapse_interval 0 timelapse_mode daily movie_bps 500000 movie_quality 2 timelapse_codec swf snapshot_interval 2 locate_motion_mode on text_right %Y-%m-%d\n%T-%q text_left CAMERA %t text_changes on text_event %Y%m%d%H%M%S-%v text_scale 2 target_dir /data/motion snapshot_filename snapshots/camera%t/%Y/%m/%d/%H/%M/%S-snapshot picture_filename motion/camera%t/%Y%m%d/%C/%Y%m%d-%H%M%S-%q timelapse_filename timelapse/camera%t/%Y/%m/%d-timelapse stream_quality 90 stream_maxrate 5 stream_localhost off stream_port 8080 webcontrol_port 8881 webcontrol_localhost off webcontrol_interface 0 webcontrol_authentication admin:admin quiet on on_picture_save echo %f >> /tmp/motion.capture thread /etc/motion/conf.d/driveway.conf

Starting motion, logging to a file at level 7: root@dvr:/tmp# motion -l /tmp/motion.log -d 7 [0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf [0:motion] [ALR] [ALL] conf_cmdparse: The "thread" option has been replaced by the "camera" after version 3.4.1 [0:motion] [NTC] [ALL] config_camera: Processing camera config file /etc/motion/conf.d/driveway.conf [0:motion] [NTC] [ALL] motion_startup: Logging to file (/tmp/motion.log)

The output of motion.log and motion.capture (captures the command/script output) is attached (motion.capture renamed to motion.capture.log so I can upload).

motion.log motion.capture.log

Thanks, Whytey

tosiara commented 4 years ago

How do you make snapshots?

Whytey commented 4 years ago

How do I make snapshots? Sorry, not sure I understand the question.

Motion takes the snapshot. From an IP camera. Per the snapshot_interval in the config.

The problem is the execution of scripts/commands in the on_picture_save directive - it causes excessive CPU usage to launch that command.

Whytey commented 4 years ago

Some additional info...I assume this is all right and I haven't made a numpty mistake...


root@dvr:~# uname -a
Linux dvr 4.4.0-148-generic #174~14.04.1-Ubuntu SMP Thu May 9 08:17:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Lin
ux
root@dvr:~# ls *.deb
bionic_motion_4.3.1-1_amd64.deb
root@dvr:~
```#
Whytey commented 4 years ago

Actually, closing as not an issue. I spun up a fresh, new container installed motion from the same deb and I am not seeing the same problem. I have no idea what caused the problem in the other container - could be LXD, could the the container environment, could have been motion - probably was me!

Apologies.