Managing Load

From ZoneMinder Wiki
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

A guide to managing system load with ZoneMinder (Written with IP Cameras in mind)


Zoneminder is a superb application in every way, but it does a job that needs a lot of horsepower especially when using multiple IP cameras. IP Cams require an extra level of processing to analogue cards as the jpg or mjpeg images need to be decoded before analysing. This needs grunt. If you have lots of cameras, you need lots of grunt.


Why do ZM need so much grunt? Think what Zoneminder is actually doing. In modect mode ZM is: 1. Fetching a jpeg from the camera. (Either in single part or multipart stream) 2. Decoding the jpeg image. 3. Comparing the zoned selections to the previous image or images and applying rules. 4. If in alarm state, writing that image to the disk and updating the mysql database.

If you're capturing at five frames per second, the above is repeated five times every second, multiplied by the number of cameras. Decoding the images is what takes the real power from the processor and this is the main reason why analogue cameras which present an image ready-decoded in memory take less work.


How do I know if my computer is overloaded? If your CPU is running at 100% all the time, it's probably overloaded (or running at exact optimisation). If the load is consistently high (over 10.0 for a single processor) then Bad Things happen - like lost frames, unrecorded events etc. Occasional peaks are fine, normal and nothing to worry about.

Zoneminder runs on Linux, Linux measures system load using "load", which is complicated but gives a rough guide on what the computer is doing at any given time. Zoneminder shows Load on the main page (top right) as well as disk space. Typing "uptime" on the command line will give a similar guide, but with three figures to give a fuller measure of what's happening over a period of time but for the best guide to see what's happening, install "htop" - which gives easy to read graphs for load, memory and cpu usage.

A load of 1.0 means the processor has "just enough to do right now". Also worth noting that a load of 4.0 means exactly the same for a quad processor machine - each number equals a single processor's workload. A very high load can be fine on a computer that has a stacked workload - such as a machine sending out bulk emails, or working its way through a knotty problem; it'll just keep churning away until it's done. However - Zoneminder needs to process information in real time so it can't afford to stack its jobs, it needs to deal with them right away.

For a better and full explanation of Load: http://en.wikipedia.org/wiki/Load_%28computing%29


My load is too high, how can I reduce it? Zoneminder is /very/ tweakable and it's possible to tune it to compromise. The following are good things to try, in no particular order;

Change the jpeg libraries. In most distributions Linux uses standard jpeg libraries which although fine for most things, don't use the MMX functions in nearly all modern processors. Check whether your cpu supports mmx by running "cpuid |grep MMX" which should give you a line or two along the lines of "MMX instructions". If so, give the libs a try. Most people report their load halves simply by using these libs. http://www.zoneminder.com/forums/viewtopic.php?t=6419 gives more info. Nobody's posted there to say it broke their system... Yet.

If your camera allows you to change image size, think whether you can get away with smaller images. Smaller pics = less load. 320x240 is usually ok for close-up corridor shots.

Go Black and White. Colour pictures use twice to three times the CPU, memory and diskspace but give little benefit to identification.

Reduce frames per second. Halve the fps, halve the workload. If your camera supports fps throttling (Axis do), try that - saves ZM having to drop frames from a stream. 2-5 fps seems to be widely used.

Experiment with using jpeg instead of mjpeg. Some users have reported it gives better performance, but YMMV.

Tweak the zones. Keep them as small and as few as possible. Stick to one zone unless you really need more.

Schedule. If you are running a linux system at near capacity, you'll need to think carefully about things like backups and scheduled tasks. updatedb - the process which maintains a file database so that 'locate' works quickly, is normally scheduled to run once a day and if on a busy system can create a heavy increase on the load. The same is true for scheduled backups, especially those which compress the files. Re-schedule these tasks to a time when the cpu is less likely to be busy, if possible - and also use the "nice" command to reduce their priority. (crontab and /etc/cron.daily/ are good places to start)


More expensive options:

Increase RAM. If your system is having to use disk swap it will HUGELY impact performance in all areas. Again, htop is a good monitor - but first you need to understand that because Linux is using all the memory, it doesn't mean it needs it all - linux handles ram very differently to Windows/DOS and caches stuff. htop will show cached ram as a different colour in the memory graph. Also check that you're actually using a high memory capable kernel - many kernels don't enable high memory by default.

Faster CPU. Simple but effective. Zoneminder also works very well with multiple processor systems out of the box (if SMP is enabled in your kernel). The load of different cameras is spread across the processors.


What about disks and bandwidth?

In most modern pc-based servers, disk I/O is more than adequate for the speeds involved in capturing from multiple cameras in most scenarios.

A typical 100mbit LAN will cope with most setups easily. If you're feeding from cameras over smaller or internet links, obviously fps will be much lower.

Disk and Bandwidth calculators are referenced on the Zoneminder wiki here: http://www.zoneminder.com/wiki/index.php/FAQ#How_much_Hard_Disk_Space_.2F_Bandwidth_do_I_need_for_ZM.3F