Speed up ZM with Lingerd

Add any particular hints or tricks you have found to help with your ZoneMinder experience.
Post Reply
User avatar
kingofkya
Posts: 1110
Joined: Mon Mar 26, 2007 6:07 am
Location: Las Vegas, Nevada

Speed up ZM with Lingerd

Post by kingofkya »

http://www.iagora.com/about/software/lingerd/
Lingerd is a daemon (service) designed to take over the job of properly closing network connections from an http server like Apache.

Because of some technical complications in the way TCP/IP and HTTP work, each Apache process currently wastes a lot of time "lingering" on client connections, after the page has been generated and sent. Lingerd takes over this job, leaving the Apache process immediately free to handle a new connection. As a result, Lingerd makes it possible to serve the same load using considerably fewer Apache processes. This translates into a reduced load on the server.

Lingerd is particularily useful in Apache webservers that generate dynamic pages (e.g in conjunction with mod_perl, mod_php or Java/Jakarta/Tomcat).

More importantely, lingerd can only do an effective job if HTTP Keep-Alives are turned off; since keep-alives are useful for images, the recommended lingerd setup is to have an Apache/mod_whatever/lingerd server for the dynamic pages, and a plain Apache (or thttpd or boa) for the images.
I dont know how manny of you have had issuse with zm/apache being slow and just dropping frequently form flipping though events.

I have a solution and its really easy don't be scared of the compiler

First make a build directory

Code: Select all

mkdir build
Move into the build directory

Code: Select all

cd build
Get the tarball

Code: Select all

wget http://images.iagora.com/media/software/lingerd/lingerd-0.94.tar.gz
Unpack tarball

Code: Select all

tar zxf lingerd-0.94.tar.gz
Move into extracted archive

Code: Select all

cd lingerd-0.94
compile

Code: Select all

make
copy compiled file to /usr/bin

Code: Select all

cp lingerd /usr/bin/lingerd
add permisions for execution

Code: Select all

chmod a+x /usr/bin/lingerd
Now in order for this demand to start it must run before apache starts. So you can make a rc.d or init.d file for lingerd but then theres a change you could make it start before httpd.


my solution is just add it to apaches rc.d or init.d file (note this will differ per distro.)
On arch linux

Code: Select all

nano /etc/rc.d/httpd
Heres what my rc.d looks like. The changes are between
##EDIT START
##EDIT END

Code: Select all

case "$1" in
  start)
    stat_busy "Starting Apache Web Server"
##EDIT Start 
    /usr/bin/lingerd
##EDIT END
    if $APACHECTL start &>/dev/null ; then
      add_daemon $daemon_name
      stat_done
    else
      stat_fail
      exit 1
    fi
    ;;

  stop)
    stat_busy "Stopping Apache Web Server"
##EDIT START
    pkill lingerd
##EDIT END
    if $APACHECTL stop &>/dev/null ; then
      rm_daemon $daemon_name
      stat_done
    else
      stat_fail
      exit 1
    fi
    ;;
Also remember to edit
httpd.conf and turn off keep alive other wise all that work would be for nothing.


Now you can take back all that mem httpd was wasting.
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy »

ps -ef|grep lingerd doesn't show nothing... what gives???


I got this error...
lingerd[3242]: bind() failed: No such file or directory
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy »

Ok, so you need to create /var/run/lingerd/ dir and make it user permissible... and I have Fedora 10 so httpd is on /etc/rc.d/init.d/httpd and the modifications were like...

Code: Select all

start() {
	/usr/bin/lingerd  // THIS LINE WAS ADDED...
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd a delay of >10 second is required before SIGKILLing the
# httpd parent; this gives enough time for the httpd parent to SIGKILL any
# errant children.
stop() {
	pkill lingerd   // THIS LINE WAS ADDED...
	echo -n $"Stopping $prog: "
	killproc -p ${pidfile} -d 10 $httpd
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    pkill lingerd  // THIS LINE WAS ADDED...
    /usr/bin/lingerd  // THIS LINE WAS ADDED...
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy »

Does not work with IE only Firefox, and it does seems to speed up things just a little bit...
User avatar
kingofkya
Posts: 1110
Joined: Mon Mar 26, 2007 6:07 am
Location: Las Vegas, Nevada

Post by kingofkya »

it is browser independent because apache servers each one the same way
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy »

Could it be that I received some warnings at the compilation time???

Nevermind... it just takes alittle bit longer for the images to appear...
User avatar
kingofkya
Posts: 1110
Joined: Mon Mar 26, 2007 6:07 am
Location: Las Vegas, Nevada

Post by kingofkya »

wierd mine came faster might just have been the tine of day though. also for some reason on arch linux i did not have to add that var folder/file
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Post by knight-of-ni »

Hey guys,
I had a moment of opportunity to check out lingerd. Despite a couple of warnings, it compiles on 64bit centos 5.4.

Don't know if anyone noticed, but in the "extra" subfolder, there is a startup/shutdown script which should work on any Redhat/Fedora/CentOS type system. One should be able to copy the script to /etc/init.d and use chkconfig to enable it (and prioritize it to start before apache).

I have not yet tried the script myself, because at the moment I'm mentally stuck on the following: According to the lingerd documentation, it was developed for the now old Apache 1.3.x. Also, it looks like one must modify and recompile the Apache source to specifically make use of lingerd.

Consequently, if one is running a modern Linux distro, which uses Apache 2.2.x presumably compiled w/ no knowledge of lingerd, I don't understand how lingerd could work at all. How does Apache know to make use of lingerd in this case? Is my logic off track somewhere? I'm hoping someone can enlighten me because according to this thread it seems that lingerd somehow does make a difference.
Post Reply