Emacs w/o .Xresources file
Maybe you've read about the wonderful work in progress of Behad on gnome-session and have seen .Xresources will be not read anymore during GNOME startup (bug #557807). Don't cry Emacs addict, you've two solutions, see a therapist to heal from the Stockholm Syndrom and use gedit or install Emacs GTK+ and add these settings to your .emacs (and so delete your .Xresources file):
(setq default-frame-alist
(append default-frame-alist
'((background-color . "rgb:3a/38/35")
(foreground-color . "rgb:d3/d7/cf")
(cursor-color . "yellow")
(font . "fixed"))))
PS: I find these colors pretty with the nice Dust Theme
PS2: this solution works fine with frames (Ctrl+x 5 2)
Database performance in Web applications
It's more efficient to connect a Web application with an Unix Domain
Socket than TCP/IP one (reduced overhead) so I'll explain the required
configuration with the following pairs:
1 - TurboGears/SQLAlchemy
2 - Django/PostgreSQL
3 - Django/MySQL
1 - TurboGears/SA
SQLObject is dead, isn't it? So With SQLalchemy, the syntax is:
sqlalchemy.dburi="postgres:///dbname?user=mydbuser&password=XXXXXX" ([1])
http://docs.turbogears.org/1.0/DatabasePostgres
2 - Django/PostgreSQL
You just need to define DATABASE_ENGINE = 'postgresql_psycopg2' and DATABASE_NAME. Leave DATABASE_HOST setting empty to use UDS.
3 - Django/MySQL
Create a database in UTF8, either with default-character-set = utf8
under [mysqld] section in the my.cnf file or with an explicit 'create
database bla charset=utf8;'
In settings.py:
DATABASE_HOST = '/var/run/mysqld/mysqld.sock'
DATABASE_OPTIONS = {
'read_default_file': '/etc/mysql/my.cnf',
'init_command': 'SET storage_engine=INNODB'
}
A - Note about PostgreSQL
When the user isn't the same one who runs the process, you must edit the PostgreSQL configuration (/etc/postgresql/8.3/main/pg_hba.conf):
# "local" is for Unix domain socket connections only
local user database md5
local all all ident sameuser
You must create an user with a encrypted password (encrypted by default).
$ CREATEUSER username
$ psql
postgres=# ALTER USER username WITH ENCRYPTED PASSWORD 'my_password';
If you want to be sure, remove the lines with 'host' to deny nonlocal connections.
Saving power with Linux and reducing the boot time
There are a great web site and some tools about this subject (thanks to Intel and their great developers)
http://www.lesswatts.org
Services
The first step is to remove some useless services or rarely used, I chosen the following ones :
apt-get remove bluz-utils hplip* scim* tracker*
update-rc.d -f pcmcia remove, for mysql, apache2, postgresql-8.3 (it's easy to launch when necessary)
You can really check the impact of your changes with bootchart and view the result with eog /var/log/bootchart/*.png (my laptop starts in 27 seconds).
In gnome-session-properties, I also unchecked Applet Tracker, Evolution Alarm Notifier, Bluetooth Manager (don't forget to save in the third tab).
Settings
You can measure the number of wakeups per second with the wonderful PowerTop ($ sudo powertop), on my computer the main guilty was the proprietary nvidia driver (around 60 fps like the refresh rate of my screen), I added the following line in my xorg.conf to resolve that issue (~ 2 wps after) :
Option "OnDemandVBlankInterrupts" "true"
I also blacklisted some modules in /etc/modprobe.d/blacklist
blacklist pcmcia
blacklist yenta_socket
blacklist rsrc_nonstatic
With no Wifi and no USB mouse connected, with my GNOME Desktop, a gnome-terminal and Emacs, I have only 20 wakeups per second (not bad
.
I wrote a little script to test some more aggressive settings if they works fine I will add them to sysctl.conf:
# By setting this to '1', under light load scenarios, the process
# load is distributed such that all the cores in a processor package
# are busy before distributing the process load to other processor
# packages.
echo 1 > /sys/devices/system/cpu/sched_mc_power_saving
# From 500 by default
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
# SATA
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
# Sound
echo 1 > /sys/module/snd_hda_intel/parameters/power_save
I don't use the laptop_mode or hdparm because I don't want to stress my hard drive with too many spin up and down. It's not necessary to insert the 'noatime' option in fstab with Ubuntu Hardy Heron because the new 'relatime' option is already activated.
Reduce open calls on Ubuntu
You've installed a fresh Ubuntu and you're not English. Just try:
$ strace gnome-terminal
and you'll see this long list of calls only to open gtk20.mo (12 calls on Hardy Heron):
open("/usr/share/locale/fr_FR.UTF-8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/fr_FR.utf8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/fr_FR/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/fr.UTF-8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/fr.utf8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/fr/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/fr_FR.UTF-8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/fr_FR.utf8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/fr_FR/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/fr.UTF-8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/fr.utf8/LC_MESSAGES/gtk20.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/fr/LC_MESSAGES/gtk20.mo", O_RDONLY) = 3
There are many solutions to workaround this performance problem, either you use my little script reduce-mo-open-calls.sh which detect your current locale and create only some symlinks, or you can try someting more adventurous (I don't know the result after a upgrade of your langpack), move /usr/share/locale-langpack/fr/LC_MESSAGES/* to /usr/share/locale/fr/LC_MESSAGES/ and create the following symlinks after deleting of /usr/share/locale-langpack/fr:
ln -s /usr/share/locale/fr /usr/share/locale-langpack/fr
then from /usr/share/locale/, /usr/share/locale-langpack and /usr/lib/locale:
ln -sfvT fr fr_FR.UTF-8 ln -sfvT fr fr_FR.utf8 ln -sfvT fr fr.UTF-8 ln -sfvT fr fr.utf8 ln -sfvT fr fr_FR
If someone knows a better solution to configure the paths order, I'm interested! I'm intend to post a bug report if I don't see any strange systems calls in the next weeks.
This hack removes 89 open calls at the launch of gnome-terminal (the result is better with bigger applications), it's pretty nice, isn't it?
Waf build system
I integrate the Waf build system to libmodbus. Waf is a really nice project I hope Thomas Nagy will have time to update his documentation. The code is small and really easy to browse but the most impressive difference is the execution time:
time (./autogen.sh && ./configure && make && sudo make install)
=> 21.576s (with AM_DISABLE_STATIC)
time (./waf configure && ./waf build && sudo ./waf install)
=> 2.779s
The output is nice (compact and colorful), you can also use Waf in daemon mode (works with inotify) and each time a file of your project is modified, Waf build the new component. The size of the configure script is ~700Kb and if you choose to embed Waf it's only 100Kb. Last but not least, your build system doesn't check for Fortran anymore
.
Thanks to Ali Sabil for his demonstration of Waf at FOSDEM!
Performance of a PHP application with APC
To evaluate the performance of Vertimus with a opcode cache like APC, I used xdebug and Kcachegrind.
The results are really interesting, without APC, the index page has a total time cost of 191 032, the Zend Framework requires to use many classes, PHP is not really fast to parse and execute this code :
and with APC, the total time cost is only 123 904:

The CPU load is reduced by 36% but you need a bit of memory to store cache data (30 Mo by default). The results has been obtained with APC 3.0.16 and the following configuration:
;;;;;;;;;;;;;;;;;;
; APC ;
;;;;;;;;;;;;;;;;;;
extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=30
apc.ttl=7200
apc.user_ttl=7200
Cairo-Clock is now really faster!

Cairo-Clock is CPU intensive and consume around 13 % of CPU on my Core 2 Duo (on one CPU), the workload is spread on Xorg (10 %), compiz.real (2 %) and cairo-clock (1 %) with a smoothing value defined at 30 (default). The second hand drawing is disabled (default).
I wrote some patches to reduce the CPU consumption and now, Cairo-Clock doesn't appear in 'top' list, woooh! The solution was simple, it useless to refresh the clock at 30 Hz if the second hand is not drawn. I also use common code to manage timeout and g_timeadd_seconds reduce the number of interrupts when many applications use this function.
I prefer bzr to git but I published my patches on github so MacSlow can take my patches here: http://github.com/stephane/cairo-clock/tree/master
PS: I couldn't resist to translate in French (and fix Cairo-Clock for translation).
Performance work – g_return
Huge performance work is actually doing by the Gnome team. I participated to an IRC session 2005-10-30, The Performance Love Day, a discussed task is to replace :
- g_return_if_fail by g_assert or nothing (g_assert can be disabled at compile time)
- g_return_val_if_fail by if/then or nothing
I wrote a simple tool find-static-g-return.py (2005-10-30) to do that but it doesn’t work (if you have some time, look at this).
Note: I can contact aaditya at sood dot net dot in about this.
