MySQL bind_address workaround
MySQL has an ugly design fault preventing it to listen more than one interface in its bind_address my.conf directive. Thus, you usually cannot connect to the same MySQL instance using localhost and external IP sources.
Here is a workaround based on xinetd daemon. These are sample commands for Ubuntu/Debian.
Go to root
sudo -i
Install xinetd
apt-get install xinetd
Add a new xinetd mapping
pico /etc/xinetd.d/mysql
service mysql
{
only_from = localhost mansikki.redinnovation.com 80.75.108.108 server213-171-218-5.livedns.org.uk 213.171.218.5
flags = REUSE
socket_type = stream
wait = no
user = root
redirect = 127.0.0.1 3306
log_on_failure += USERID
interface = 84.34.147.68
}
Restart xinetd
/etc/init.d/xinetd restart
To debug xinetd:
/etc/init.d/xinetd stop
xinetd -d
xinetd only_from directive also gives an access control by allowed source IP addresses. This protects your MySQL against bots and brute force attacks.
Note that iptables DNAT translation doesn’t work (easily). Localhost packets don’t travel PREROUTING and POSTROUTING chains.
How to encode h264 video files for Nokia Series 60 standalone playback
Bored with Spiderman 3 which came with your Nokia N95 8 GB? This guide shortly tells how to get movies into your N95 on Ubuntu Linux using ffmpeg video encoder. The aim is to encode video suitable for playback from Nokia N-series (N95, N78, others) mobile phone memory card. We use h264 + AAC codecs which provides the best quality/compression rate for Nokia phones currently.
Ubuntu does not distribute proprietary codes. First thing you need to do is to rebuild ffmpeg. Since Ubuntu 8.04 Hardy Heron ships with ffmpeg from 2007, which is aeons old in video codec years, you need to build libx264 and ffmpeg from SVN sources. Here are detailed, valid, instructions. Note that FFMPEG trunk is not currently stable (September 2008), so you need to use revision 15261 which needs this little patch. Indeed, this is a very difficult month to start your career in the dark world of video encoders.
To make it legal and support open source codec development, please pay for your codecs.
Then we use this guide by Robert Swain. We have a tiny sub 2,4″ screen, we do not care about the quality and do one pass encoding. By empirical research, I have found that the following MPEG-4 profile parameters are compatible with N95 8 GB and provide the optimal result. You can vary video and audio bitrate depending on your taste.
Here is a script which recursivelu encodes all detected video files suitable for mobile format:
#!/bin/sh
#
# Optimal movie encoding for Nokia N-series mobile phones
#
# Copyright 2008 Red Innovation Ltd.
#
# Say hi if you find this useful.
# We do some professional mobile video publishing, so if you
# need a helping hand please call us.
#
# Usage: Run encode.sh in any folder and all video files are recursively converted to mobile phone suitable format
#
# Note: We expect all the source material be in 16:9 aspect ration
#
# Also see http://www.nseries.com/index.html#l=support,search,faq,general,video%20encoding,53848
#
VIDEO_BITRATE=300k
AUDIO_BITRATE=72k
# Assume locally build ffmpeg + x264 in /usr/local/bin
# http://ubuntuforums.org/showthread.php?t=786095
export LD_LIBRARY_PATH=/usr/local/lib
# Search all source AVI, MPG and WMV video files
# Place all encoded files to the same folder with the source, with added .mp4 extension
find . -iname "*.avi" -or -iname "*.wmv" -or -iname "*.mpg" | while read src ; do
srcfile=`basename "$src"`
srcfolder=`dirname "$src"`
dstfile="$srcfolder"/"$srcfile".mp4
# The magical string!
# Size and cropping is for 16:9 source material, so that 320:240 display will have black bars.
# Fex pixels off... note that h264 sizes must be multiplies of 16, use 256x144 for streaming
# N95 RealMedia player does not seem to respect MPEG-4 embedded aspect ration info.
/usr/local/bin/ffmpeg -y -i "$srcfile" -acodec libfaac -ab $AUDIO_BITRATE -s 320x176 -aspect 16:9 -vcodec libx264 -b $VIDEO_BITRATE -qcomp 0.6 -qmin 16 -qmax 51 -qdiff 4 -flags +loop -cmp +chroma -subq 7 -refs 6 -g 250 -keyint_min 25 -rc_eq 'blurCplx^(1-qComp)' -sc_threshold 40 -me_range 12 -i_qfactor 0.71 -directpred 3 "$dstfile"
done
Zope Zeo vs. standalone setups
We do some Plone development here at Redi. As known, Plone is a powerful, but unfortunately quite a heavy CMS which is best suited for Intranets. Thus, we are always looking for speed increase.
Enter Zeo cluster - a feature that nowadays comes bundled with Zope and allows one database (practically Data.fs) to be used by multiple Zope instances, or more accurately Zeo clients. In standalone installation only one CPU / CPU core can be used for processing requests (as Zope / Python implementation is single-threaded AFAIK). So if there are any concurrent requests the database (ZODB, the Zope Object Database) usually has to wait for the request processing before it is asked for the data and only part of the processing power is used as requests are queued. Using Zeo server-client architecture however, each Zeo client can do the processing on their own CPU/core (thus efficiently using the whole CPU prosessing power available) and also minimize the hard disk idle time by asking for data in an ~asynchronous manner (in separate queues). Actually ZODB even serves the same object simultaneously to different client processes for performance reasons. This might raise database ConflictErrors, which are nothing to fear of, however, as noted some paragraphs below.
Similarly, you could also deploy Zeo clients on different computers in local network (or wherever you want), but that’s not the scope of this article. Having clients running on different machines is a similar case with the same performance basis, but there are connection lags, bandwith limits and such that decrease performance.
Theory vs. practice
Deploying a Zeo cluster instead of standalone Zope instance should theoretically increase the performance by factor of extra available CPUs / CPU cores. There might be some overheads from this setup though, so we tested it out using ApacheBenchmark - the benchmarking module that comes bundled with Apache nowadays. But first something about…
Setting up Zeo & converting from standalone mode
In the easiest scenario, setting Zeo up is rather easy: the unified installer supports Zeo-server setup out of the box (=there is a recipe for it). Just run the unified installer like:
$ ./install.sh zeo
Luckily, the unified installer uses buildout from Plone 3.1 onwards. Thus, converting your current buildout instances to Zeo cluster is nothing but change of buildout configuration. Where you would normally need ‘instance’ section in your buildout.cfg you will now need the following:
[zeoserver]
recipe = plone.recipe.zope2zeoserver
zope2-location = ${zope2:location}
zeo-address = 127.0.0.1:12000
#effective-user = __EFFECTIVE_USER__
[client1]
recipe = plone.recipe.zope2instance
zope2-location = ${zope2:location}
zeo-client = true
zeo-address = ${zeoserver:zeo-address}
# The line below sets only the initial password. It will not change an
# existing password.
user = admin:mysecretpassword
http-address = 12001
#effective-user = __EFFECTIVE_USER__
#debug-mode = on
#verbose-security = on
# If you want Zope to know about any additional eggs, list them here.
# This should include any development eggs you listed in develop-eggs above,
# e.g. eggs = ${buildout:eggs} ${plone:eggs} my.package
eggs =
${buildout:eggs}
${plone:eggs}
# If you want to register ZCML slugs for any packages, list them here.
# e.g. zcml = my.package my.other.package
zcml =
products =
${buildout:directory}/products
${productdistros:location}
${plone:products}
To add more clients (which is quite the point here), append as many times the extra client sections like this:
[client2]
recipe = plone.recipe.zope2instance
zope2-location = ${zope2:location}
zeo-client = true
zeo-address = ${zeoserver:zeo-address}
user = ${client1:user}
http-address = 12002
#effective-user = __EFFECTIVE_USER__
#debug-mode = on
#verbose-security = on
eggs = ${client1:eggs}
zcml = ${client1:zcml}
products = ${client1:products}
That minimizes the need for retyping user names, password etc. These examples were taken from Plone unified installer buildout.cfg with ports changed.
Starting, stopping & restarting
Now, to start your Zeo-powered Plon clients you could type:
bin/zeoserver start bin/client1 start bin/client2 start ...same for all the clients...
However, the unified installer has a recipe which automatically generates nice and simple shell scripts to control your cluster. In the end of your buildout.cfg, add:
[unifiedinstaller]
recipe = plone.recipe.unifiedinstaller
user = ${client1:user}
primary-port = ${client1:http-address}
That should generate the scripts. In fact, it propably does also something else, something which I’m not aware of. However, I didn’t bump into any problems, yet
Anyway, to start the whole cluster (server & clients), type:
bin/startcluster.sh
And that does it (it start server and the clients). Shut it down via:
bin/shutdowncluster.sh
And restart:
bin/restartcluster.sh
ConflictErrors - not that errerous
As noted before, in Zeo mode the ZODB might serve the same objects to two more clients at the same time. If one client manipulates the object before others (ie. edits values and saves changes) the other requests will propably fail. This raises ConflicError which looks like this:
ConflictError: database conflict error (oid 0x0f39, class HelpSys.HelpSys.ProductHelp)
In this case ZODB tries to reprocess the failed requests. This should be common database approach and thus a feature, not a bug (although Zope might want to tell that in error message!). For more accurate explanation see Plone discussion.
Parsing it together with web server
The Zeo components (server and clients) talk to each other via standard Internet protocols (TCP or UDP, not sure). In the default setup, the Zeo server listens to port 8100 and Zeo clients to 8080, 8081, etc. Thus, to access the separate clients as ‘one site’ we need to serve the requests to multiple clients. This can be achieved with load balancers. Apache has at least one: mod_proxy_balancer which should do exactly what we need. Apache isn’t the best choice for achieving high requests per second values, but it will do for our tests (compare to more lightweight but also more limited lighttpd). Just remember that there are other alternatives/methods available, like using squid as load balancer.
Our configuration is as follows (inside VirtualHost-directive):
<Proxy balancer://lb>
BalancerMember http://127.0.0.1:12001/
BalancerMember http://127.0.0.1:12002/
BalancerMember http://127.0.0.1:12003/
BalancerMember http://127.0.0.1:12004/
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>
ProxyPass /balancer-manager !
ProxyPass / balancer://lb/http://localhost/VirtualHostBase/http/www.mydomain.com:80/plonesite/VirtualHostRoot/
ProxyPassReverse / balancer://lb/http://localhost/VirtualHostBase/http/www.mydomain.com:80/plonesite/VirtualHostRoot/
This setup also allows us to use the balancer-manager (accessible at /balancer-manager) that comes with mod_proxy_balancer. It’s useful for checking if the configuration is working and balancer is dividing the requests equally. In my setup the balancer is using the default Request Counting -algorithm which divides the requests numerically equally between the instances, but you might want to also try Weighted Traffic Counting, which should be for actual use. In our test only the frontpage is accessed however, so each request’s data transfer is equal and the weighted traffic counting isn’t of use.
The test
The server machine
- Ubuntu 8.04 virtual server
- Intel Xeon 2.0Ghz (4 cores)
- 2 GB of RAM
- Hard disk drive (7200rpm?)
The setup
- Standalone Plone instance
- Plone via Zeo server with 4 clients (as many clients as cores in processor)
- Plone via Zeo server with 6 clients (for curiosity)
The tests where run locally in development environment to minimize the network lag (was 0-1ms).
The test commands
ApacheBenchmark commands:
$ ab -n N -c C myurl
where N was either 1000 or 9000 (requests) and C 1, 10, 100 or 1000 (concurrent requests).
The results
You can download the more in-depth test sheet Plone Standalone vs. Zeo installation (PDF).
To put it simple: theory and practise meet well - Zeo server is a lot more powerful with concurrent requests. On non-concurrent requests the results are about the same.
Having as many Zeo clients as CPUs / CPU cores can boost the performance up to number of extra CPUs/cores. For example, in our quad-core server with Zeo setup we gained nearly 4 times the requests per second of standalone installation (~370% to be accurate). Increasing Zeo clients to 6 didn’t help any as there’s no processing power left from 4 heavily stressed client processes. Also to be noted is that the waiting times for clients nearly tripled (median jumped from 126 to 305 ms) when raising concurrency from 1 to 10. This isn’t bad though - those are still low figures compared to standalone’s median of 1215 ms! Only when raising concurrency to 100 we began to see some 3,6 seconds waiting times (6 seconds for standalone). Increasing concurrency didn’t bring down the requests/second rates much (less than 5%) as expected.
Overall, the results were expected, but now we have evidence of it: under concurrent request load Zeo server is a good option to multiply the performance of your site. With very low traffic sites which rarely get more than 1 request at time this doesn’t matter.
One bad word about the resource requirements though: The used RAM increase for 6 client Zeo setup (standard Plone 3.1.2 + 12 additional Products) was whopping 621 MB (1132 MB -> 1753 MB). That means about 100 MB per Zeo client as the Zeo server memory intake was only about 12-15 MB. Thus, only use as many Zeo clients as absolutely necessary or you might find your beloved server machine under very serious Zope flu!
Wrong swap UUID after hibernation in Feisty
I’ve been using uswsusp for suspending/hibernating my Ubuntu Feisty laptop but suddenly it failed to resume from disk hibernation (blank screen with blinking cursor). I booted up in restoration mode and Ubuntu reported that it couldn’t restore the snapshot. After pressing enter to continue, the system booted up just fine, skipping the snapshot restoration as supposed. The startup problem vanished, but it brought up a new one when trying to hibernate:
>>> sudo s2disk Could not use the resume device (try swapon -a)
Of course, swapon also gives a problem:
>>> sudo swapon -a swapon: cannot stat /dev/disk/by-uuid/4a815ae8-fa5b-4265-826c-d777a723e87b: No such file or directory
It seems that the UUID reference for swap is broken. Or is it the swap? At this point I did some Google research and it turned out the behaviour was because of an Ubuntu Feisty bug, which causes the swap UUID change occasionally. It is closely related to hibernation, yet the cause remains unclear. To fix it, let’s do:
>>> free -m | grep -i swap Swap: 0 0 0
Which indicates that the system doesn’t find swap at all (because of wrong UUID). To find correct one:
>>> sudo fdisk -l | grep swap /dev/sda6 10669 10917 2000061 82 Linux swap / Solaris
Find your swap there and go for:
>>> sudo vol_id /dev/sda6 ID_FS_UUID=083d41f0-de57-48d4-92eb-aefde8fd6ec9
Then you’ll just have to edit it in /etc/fstab and hibernation should work again. You could also try restoring the original snapshot by editing:
>>> sudo nano /etc/initramfs-tools/conf.d/resume
and correcting the reference there also. I didn’t test this myself, however.
That should do it, but don’t get too excited: some report that the UUID keeps changing even after the fix, and it has to be manually changed over and over again. Luckily, I haven’t experienced such behaviour (yet!) and it’s quick to fix (though you might lose ability to hibernate, which is a really bad thing).
Printing to Windows Vista printer from Linux
Today my head hurts. It appears that Linux clients cannot access Microsoft Windows Vista shares or printers, because Microsoft changed sharing protocol from SMB to SMB2 in Windows Vista. In theory, if the client doesn’t support SMB2, Vista server should fall back to old and faithful working SMB. In practice, Linux Samba clients have a bug (still in Ubuntu Feisty Fawn and Samba 3.0.24) and this doesn’t happen.
You get this error to CUPS logs:
E [20/Aug/2007:18:43:25 +0300] [Job 141] No ticket cache found for userid=1000 E [20/Aug/2007:18:43:25 +0300] [Job 141] Can not get the ticket cache for moo E [20/Aug/2007:18:43:25 +0300] [Job 141] Session setup failed: NT_STATUS_LOGON_FAILURE E [20/Aug/2007:18:43:25 +0300] [Job 141] Tree connect failed (NT_STATUS_ACCESS_DENIED) E [20/Aug/2007:18:43:25 +0300] [Job 141] Unable to connect to CIFS host, will retry in 60 seconds...
Even worse, CUPS and Gnome UI fail silently. The printer shows a status “still printing” and no error is reported to the user
You can still print to Windows Vista server if you install LPD printer sharing on Windows Vista. Both CUPS printer manager and Vista supports LPD protocol for printing. Follow these excellent instructions.
Now, back to the work after 3 hours of unneeded bang-my-head-to-wall.
EDIT: This seems to be fixed in Samba 3.0.25.
RSS