Taking advantage of multiple cores

I just got a new computer with an i7 processor ( 4 cores x 2 threads per core). I am now far more aware of the dismal state of user software that is not multi-threaded. Many tasks that I expected to run much faster, are just as slow since they are not able to take advantage of the extra cores.

One of the more time consuming tasks that I execute, is video encoding. After taking movies of my kids, I like to convert them, and save on my hard-drive in a more friendly format than that in my camera. Also, if I want to edit them with a non-linear editor, this would require me to convert them usually to mpeg2 format.

I use Mencoder for converting these files, and noticed that it is single-threaded. So, in order to take advantage of the multiple cores, I split the mpeg file into multiple pieces, and run multiple encoding streams in parallel.

Here is an example of running this on a short movie:

First without parallel encoding streams:

malcolm@Blue:~/Demo$ time mencoder -o dvd2.avi -ovc lavc -oac copy dvd.avi >& /dev/null

real    6m32.538s
user    6m11.470s
sys    0m7.210s

Now, running four mencoders in parallel:

malcolm@Blue:~/Demo$ time ./go
Avisplit: Mon Dec 14 12:27:12 IST 2009
Mencoder: Mon Dec 14 12:27:31 IST 2009
Avimerge: Mon Dec 14 12:29:26 IST 2009
Complete: Mon Dec 14 12:29:44 IST 2009

real    2m32.816s
user    6m15.510s
sys    0m17.530s

So, we have speeded up in total around 3x. This includes the extra overhead of splitting and recombining the files once encoding has completed.

This is a good example of how you can still improve application performance even without access to the source code itself.

Just in case you are wondering (or skeptical), here is my 'go' script:

#!/bin/bash
echo -n "Avisplit: "
date
avisplit -i dvd.avi -s 400 >& /dev/null
echo -n "Mencoder: "
date
mencoder -o dvd-0000.avi -ovc lavc -oac copy dvd.avi-0000 >& /dev/null &
mencoder -o dvd-0001.avi -ovc lavc -oac copy dvd.avi-0001 >& /dev/null &
mencoder -o dvd-0002.avi -ovc lavc -oac copy dvd.avi-0002 >& /dev/null &
mencoder -o dvd-0003.avi -ovc lavc -oac copy dvd.avi-0003 >& /dev/null &
wait
echo -n "Avimerge: "
date
avimerge -o dvd2.avi -i dvd-0000.avi dvd-0001.avi dvd-0002.avi dvd-0003.avi >& /dev/null
echo -n "Complete: "
date


Comments:

Post a Comment:
Comments are closed for this entry.
About

Application tuning, sizing, monitoring, porting on Solaris 11

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
5
6
8
9
11
12
13
14
15
16
17
18
19
20
21
22
24
25
26
27
28
29
30
   
       
Today