jpeg SIMD (MMX) success!

Support and queries relating to all previous versions of ZoneMinder
User avatar
watou
Posts: 8
Joined: Mon Jul 12, 2010 2:23 am

Maybe our setups don't depend on fast code?

Post by watou » Wed Jul 14, 2010 3:16 am

I was just looking at this document:

http://libjpeg-turbo.virtualgl.org/About/Performance

and it occurred to me that maybe certain video inputs use different JPEG code paths than other video inputs? In my case, my frames come from uvcvideo underlying V4L2, and maybe decompression is done in the driver with un-replaceable code?

Note that this is random speculation, but I'm grasping at straws. Does anyone here have deeper knowledge of cases where libjpeg[-turbo] is simply used differently with certain sources or configurations?

User avatar
knight-of-ni
Posts: 2336
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Post by knight-of-ni » Wed Jul 14, 2010 2:38 pm

That's a good point about different jpeg code paths... If you are using a capture device with a V4L driver that natively supports the card's hardware capabilities, then I would tend to agree with your speculation.

You might want to send dcommander a message through the Sourceforge project website to see what his thoughts are. He has actively responded to a previous comment of mine.

For comparison, here is a system I'm running now that has significant cpu load reduction when using libjpeg-turbo:
  • 64 bit CentOS 5.5
    Opteron 290 cpu's (i.e. has sse3 support)
    Zoneminder, libjpeg-turbo, & ffmpeg compiled from source
    Video devices are all IP based (i.e. no v4l2 devices)
As I hinted at earlier, I'm working on a repairing & upgrading a second system that will more closely match what you are trying to do. I apologize for my slowness, but I've got near back-to-back out of town trips beginning tonight, which spans over the next 1.5 weeks. I'll work on the Ubuntu machine when I can and then post my results with the libjpeg-turbo library.

In the meantime, have you have got something IP based that can stream video to zoneminder? That could help confirm or deny whether or not the v4l driver can affect things.

User avatar
knight-of-ni
Posts: 2336
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Post by knight-of-ni » Tue Jul 20, 2010 11:31 pm

Alright, I had a moment of opportunity so I ran the same test described in the libjpeg-turbo readme file.

The following results were run on a freshly built 64bit Ubuntu 10.04 System which uses an Athlon 3300+ cpu:

Code: Select all

dvr@ubuntu-dvr:~$ export LD_LIBRARY_PATH=""
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m1.129s
user	0m0.720s
sys	0m0.050s
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m1.067s
user	0m0.770s
sys	0m0.050s
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m1.099s
user	0m0.750s
sys	0m0.050s
dvr@ubuntu-dvr:~$ export LD_LIBRARY_PATH=/opt/libjpeg-turbo/lib64
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m0.741s
user	0m0.440s
sys	0m0.100s
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m0.723s
user	0m0.430s
sys	0m0.090s
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m0.734s
user	0m0.390s
sys	0m0.100s
dvr@ubuntu-dvr:~$ 
For consistency, I ran the test three times w/o libjpeg-turbo and three times with libjpeg-turbo.

Averaging each set of real time values and then dividing gives about a ~67% increase in performance when using the libjpeg-turbo library (if I did my math right).

Note that I compiled my own libjpej-turbo .deb package from source for these tests. I'll run the test again using one of the prebuilt .deb packages from the project website.
Last edited by knight-of-ni on Tue Jul 20, 2010 11:46 pm, edited 1 time in total.

User avatar
watou
Posts: 8
Joined: Mon Jul 12, 2010 2:23 am

Great info!

Post by watou » Tue Jul 20, 2010 11:44 pm

Thanks for showing how much faster libjpeg-turbo can be at compression. Obviously, any uncompressed frames that ZM has to write (to disk or a stream) will benefit nicely from using libjpeg-turbo over libjpeg.

But I think that it could also help in decompressing raw frames from JPEG (i.e., working in the other direction). For configurations that use network cameras on modect sources, I imagine ZM has to decompress every frame in order to do its analysis, which, without a hardware assist of some sort, could be a real dog.

In my setup I have V4L-based webcams, which I think deliver uncompressed frames into ZM, thereby sidestepping a performance hit that network-based cameras would incur.

Is this a correct understanding?
Last edited by watou on Tue Jul 20, 2010 11:45 pm, edited 1 time in total.

User avatar
knight-of-ni
Posts: 2336
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Post by knight-of-ni » Tue Jul 20, 2010 11:44 pm

After removing the custom .deb package, I downloaded and installed libjpeg-turbo_1.0.0_amd64.deb from the Sourceforge project website. Here are the results:

Code: Select all

dvr@ubuntu-dvr:~$ export LD_LIBRARY_PATH=/opt/libjpeg-turbo/lib64
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m0.726s
user	0m0.410s
sys	0m0.030s
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m0.701s
user	0m0.420s
sys	0m0.060s
dvr@ubuntu-dvr:~$ time cjpeg test.bmp > test_2.jpg

real	0m0.707s
user	0m0.390s
sys	0m0.130s
dvr@ubuntu-dvr:~$ 
As you can see I get about the same improvement.
Let me know if you want me to run any other tests.

User avatar
watou
Posts: 8
Joined: Mon Jul 12, 2010 2:23 am

Post by watou » Tue Jul 20, 2010 11:46 pm

knnniggett wrote:Let me know if you want me to run any other tests.
Can you test decompression (as opposed to compression) using the two different libraries?

User avatar
knight-of-ni
Posts: 2336
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Post by knight-of-ni » Tue Jul 20, 2010 11:52 pm

Yes, I sure can.
Here are my results using djpeg, rather than cjpeg:

Code: Select all

dvr@ubuntu-dvr:~$ export LD_LIBRARY_PATH=""
dvr@ubuntu-dvr:~$ time djpeg test.jpg > test_2.bmp

real	0m0.760s
user	0m0.420s
sys	0m0.120s
dvr@ubuntu-dvr:~$ time djpeg test.jpg > test_2.bmp

real	0m0.697s
user	0m0.320s
sys	0m0.120s
dvr@ubuntu-dvr:~$ time djpeg test.jpg > test_2.bmp

real	0m0.703s
user	0m0.410s
sys	0m0.100s
dvr@ubuntu-dvr:~$ export LD_LIBRARY_PATH=/opt/libjpeg-turbo/lib64
dvr@ubuntu-dvr:~$ time djpeg test.jpg > test_2.bmp

real	0m0.456s
user	0m0.150s
sys	0m0.110s
dvr@ubuntu-dvr:~$ time djpeg test.jpg > test_2.bmp

real	0m0.467s
user	0m0.190s
sys	0m0.090s
dvr@ubuntu-dvr:~$ time djpeg test.jpg > test_2.bmp

real	0m0.437s
user	0m0.170s
sys	0m0.140s
dvr@ubuntu-dvr:~$ 

User avatar
watou
Posts: 8
Joined: Mon Jul 12, 2010 2:23 am

Post by watou » Wed Jul 21, 2010 12:00 am

Thank you!

Huge improvement for people whose cameras push compressed frames into ZM for analysis.

Anyone know if this applies to Video4Linux-based cameras?

bobbozzo
Posts: 8
Joined: Fri Sep 10, 2010 9:55 pm

Post by bobbozzo » Wed Sep 15, 2010 6:23 pm

watou wrote:Thank you!

Huge improvement for people whose cameras push compressed frames into ZM for analysis.

Anyone know if this applies to Video4Linux-based cameras?
VFL cameras don't create JPEGs, but ZM will still create JPEGs when recording or when streaming to a browser, so it will help in those cases.

To anyone not sure that the new libraries are being used, you can export the library path in /etc/profile


Bob

User avatar
knight-of-ni
Posts: 2336
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Post by knight-of-ni » Wed Sep 15, 2010 10:04 pm

Understand that exporting your library path in /etc/profile will override the libjpeg library for the entire system, not just Zoneminder.

The libjpeg-turbo library is not 100% compatible with everything (yet?), which is why the documentation recommends exporting the library for one application at a time.

I found out for myself a while back that my 64bit CentOS system acted strangely with the entire system running on the libjpeg-turbo library. Your mileage may vary.

Pyrrhic
Posts: 7
Joined: Sun Feb 13, 2011 8:54 pm

Thanks & Chrome

Post by Pyrrhic » Sun Feb 13, 2011 10:01 pm

Dear Colleagues:

I too have faced speed issues (running Ubuntu 10.10 Desktop, dual core processors, Pico2000 type cards). David's library find dropped my CPU usage from 100% to the 30s, some other tweaks dropped them lower. I have also found that using Chrome, not FireFox makes a very big difference in responsiveness for the console and for single cam viewing.

Best,

P.

redxiii
Posts: 48
Joined: Thu Aug 05, 2010 1:47 am

Re: jpeg SIMD (MMX) success!

Post by redxiii » Sat May 07, 2011 2:34 am

i found a PPA for ubuntu to use. i like to use those since it will keep the software updated. https://launchpad.net/~ikoinoba/+archive/ppa/

after installing libjpeg-turbo_1.1.0-0~ppa1_amd64.deb i notice that it didn't use the lib64 directory, so i added

export LD_LIBRARY_PATH=/opt/libjpeg-turbo/lib:$LD_LIBRARY_PATH

to the /etc/init.d/zoneminder startup script, underneath the `command="$ZM_PATH_BIN/zmpkg.pl"` line

i verified zoneminder is using the turbo libraries:

Code: Select all

$ sudo lsof |grep libjpeg.so.62.0.0
zmc       7851   www-data  mem       REG              252,2   305264    3407877 /opt/libjpeg-turbo/lib/libjpeg.so.62.0.0
zma       7853   www-data  mem       REG              252,2   305264    3407877 /opt/libjpeg-turbo/lib/libjpeg.so.62.0.0
zmc       7855   www-data  mem       REG              252,2   305264    3407877 /opt/libjpeg-turbo/lib/libjpeg.so.62.0.0
zma       7857   www-data  mem       REG              252,2   305264    3407877 /opt/libjpeg-turbo/lib/libjpeg.so.62.0.0
nph-zms   8111   www-data  mem       REG              252,2   305264    3407877 /opt/libjpeg-turbo/lib/libjpeg.so.62.0.0
nph-zms   8112   www-data  mem       REG              252,2   305264    3407877 /opt/libjpeg-turbo/lib/libjpeg.so.62.0.0
$ 

load, i'm not sure has been reduced. maybe because it was already low to begin with? about 1.5 on quad core with only 2 monitors so far. on the same machine we have a montage open 24/7 for the two streams. should there be a noticeable reduction still?

ridwan
Posts: 2
Joined: Tue Oct 02, 2012 7:45 am

zoneminder always stopped

Post by ridwan » Fri Oct 19, 2012 5:55 am

hi, all..

i have a few camera used to monitor, and it's controlled by zoneminder application, but the zoneminder application service occasionally do not work properly or failed to start the services, any suggestion what should i do?

redxiii
Posts: 48
Joined: Thu Aug 05, 2010 1:47 am

Re: jpeg SIMD (MMX) success!

Post by redxiii » Fri Oct 19, 2012 4:10 pm

you should start a new topic for that, this topic is specifically regarding libjpegturbo libraries

keda
Posts: 9
Joined: Wed Jan 09, 2013 10:27 pm

Re: jpeg SIMD (MMX) success!

Post by keda » Wed Apr 17, 2013 9:10 pm

I tried the guides above installing libjpeg-turbo and it seems to have installed just fine. The problem is that I cannot get ZM to use the new library even with the export LD_LIBRARY_PATH=/opt/libjpeg-turbo/lib:$LD_LIBRARY_PATH command in /etc/init.d/zoneminder or running it before executing ZM.

An sudo lsof |grep libjpeg gives me this(yes I am running Rasp Pi):
zmc 16934 www-data mem REG 179,2 209436 32358 /usr/lib/arm-linux-gnueabihf/libjpeg.so.8.4.0
zma 16939 www-data mem REG 179,2 209436 32358 /usr/lib/arm-linux-gnueabihf/libjpeg.so.8.4.0

How can I get Zoneminder to use the libjpeg-turbo libs?

Thanks,
Keda

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests