Archive for the ‘howto’ Category

Ubuntu 11.10 performance tuning

November 19, 2011 4 comments

I recently upgraded my netbook’s OS to Ubuntu 11.10 and noticed that it’s taking longer than usual to launch programs that I use quite often. For example, it takes 7-8 seconds to launch Google Chrome, about 4 seconds to open terminal. Here’s what I did to make the os run faster without investing with a SSD disk (My root partition is using ext4 fs, skip step 1 through 3 if you are using file systems other than ext3 or ext4):
1. Add the following bold part to the root partition line in /etc/fstab


tune2fs -o journal_data_writeback /dev/sda5

/dev/sda5 is the root partition.

3. change the following line in /etc/default/grub
(bold part is added)

4. Run update-grub
5. Add the following line to /etc/sysctl.conf

NOTE: all the above changes require root privileges.

6. Reboot

The difference? It now takes about 3-4 seconds to launch Google Chrome from cold start.

Categories: howto, ubuntu

Fixing Tunnelblick (3.1.7) kernel panic problem in Lion

August 3, 2011 Leave a comment

The currently stable version (3.1.7) of Tunnelblick would cause a kernel panic in Mac Lion while a connection is being made. Workaround is to use a beta version (3.2beta28) which is available at, released 7/31/2011.

[Edit 8/18/2011] Just updated Lion to 10.7.1 last night and version 3.2beta28 seems to be unstable as well. It has caused kernel panic two times in a row. Need to keep looking for a version that works. Did a re-installation of the same version and it works afterwards.

Change windows xp’s time synchronization frequency how-to

July 28, 2011 Leave a comment

Found the solution here:

Default is set to 604800 (7 days, bloodily stupid value chosen by M$?)

Change to a smaller amount, for example, 86400 (1day) or even 3600 (1 hour) if the OS is running some time-sensitive stuff.

A system restart is required for the new setting to be in effect.

Mac OS X Lion terminal color (remote access) problem fix

July 23, 2011 18 comments

After upgrading to Lion I noticed that the Homebrew theme that I’ve been using since Snow Leopard doesn’t display colors correctly(using different colors for directories, different types of files etc.) any more when working on remote hosts via ssh (local dir colors still work though) and switching to other themes doesn’t help. After messing around with the Terminal settings I finally found the cause and a solution. It seems Lion changed the terminal type to xterm-color256 during the upgrade (don’t remember what the setting was in SL though). The solution is simple enough, just change the emulation type for terminal from xterm-color256 to xterm-color (see screenshot below).

[ Update 1/2/2012 ]
Actually found a better solution here:
1. Keep the current xterm-256color in your Mac Terminal
2. Add the following lines to your ~/.profile on your remote host

[ "$TERM" = "xterm" ] && TERM="xterm-256color"
alias ls='ls --color'


. ~/.profile
Categories: dircolor, howto, mac osx

Check apache config syntax without restarting

June 22, 2011 Leave a comment

apachectl configtest

Found from [ first section ]

Categories: apache, howto

Comparing two mysql tables containing huge number of records each

June 15, 2011 Leave a comment

Usually I use the following method to compare two mysql tables with identical structure (or one contains the subset of columns of the other):

select * from db_A.tbl_data
where (col1, col2, col3, ...) not in
(select col1, col2, col3, ... from db_B.tbl_data);

select * from db_B.tbl_data
where (col1, col2, col3, ...) not in
(select col1, col2, col3, ... from db_A.tbl_data)

[ change * to count(*) if only the number of differences is needed ]

This method works pretty well in terms of performance when
1) number of columns to be compared is not too big, usually around 10
2) there are indexes defined in each table, this is very important when number of rows to be compared in each table is huge, I’lve done comparisons between 2M rows agains 2M rows, it can take minutes to finish, even with indexes.

But I ran into performance problem the other day when I tried to compare two identical-structured tables (comparing all 15 columns) with almost 3M rows each, and each table has only 1 index defined. Queries using the first method ran very slowly and I quickly used up patience ( I waited for more than half an hour and even the first query couldn’t got finished). Without other choices, I came up with the following solution:

a) log in to mysql server
b) select * from db_A.tbl_data into outfile '/tmp/outfile_A';
c) select * from db_B.tbl_data into outfile '/tmp/outfile_B';
d) exit mysql console
e) cd /tmp; diff outfile_A outfile_B > diff
f) wc -l diff

if the result from f) is small, I can open up file diff with an editor to see what the differences are, otherwise I can use head diff and/or tail diff to take a glance at the differences. With this method, I got the results in less than 3 minutes, which is a huge improvement compared to the first method.

Categories: howto, mysql, Tip

How to get out from tmux session inside a tmux window

June 8, 2011 7 comments

Here’s how I got stuck:
1) Remote access to a linux serverA
2) Launch tmux, Ctrl-b c to create a new window
3) From the new window, remote access to serverB, then run tmux att under shell to attach an existing tmux session (on serverB)
4) Now if I use the shortcut key Ctrl-b d, I can only detach from the session on serverA, because the tmux session on server B also uses Ctrl-b as the prefix

The fix:
a) Press Ctrl-b n until the window containing the ssh session to server B becomes the current window
b) Press Ctrl-b :
c) Enter tmux command set -g prefix C-a
d) Press Ctrl-b d, tmux session on serverB is now detached, type exit to close the new window created in step 2, this step is optional though as the “nested” tmux session is detached from the ssh shell
e) Press Ctrl-a :
f) Enter tmux command set -g prefix C-b

Step c changes prefix to Ctrl-a so it won’t conflict with the tmux shortcut prefix from serverB. Step f changes the prefix back to Ctrl-b for serverA.

Categories: howto, Tip, tmux

Debugging php scripts with php-cli

June 7, 2011 Leave a comment

Yet one can use ini_set("display_errors", 1); in php scripts to turn on error reporting (which might sometimes output a blank, dont-know-what-goes-wrong web page due to some simple syntax errors), there’s another quick and simple way to find all the syntax errors before even run it for the first time, and that is php command line (assuming that the php CLI is installed):
php -l script_name.php

What it does is checking for any syntax erros in the file script_name.php. I use this technique quite often to examine php scripts before I copy them to the web server.

Categories: debugging, howto, php

Comparing huge text files with rdiff

June 7, 2011 Leave a comment

I happened to need to compare two huge data files (plain texts), each of which is near 2GBs in size. When I use the good old diff program on a Centos with 2GB of Ram and 512MB of SWAP, pretty quickly I got stuck with this error: diff: memory exhausted.

A little googling pointed me to the following solution

Categories: howto, linux, rdiff, Tip

Capture tmux output – the much less painful way

April 7, 2011 8 comments

Before I found out this, I had to enter scrolling mode, using mouse to select/copy content to system clipboard. Those days have gone as the following will definitely speed things up a lot:

1) tmux a
2) ^b [
3) ^ space
4) move cursor with arrow keys and/or pageup/pagedown keys
5) ^ w
6) ^b ]
7) ^b:
8) save-buffer ~/out_file

2) enters copy mode
3) starts the selection
5) copies to buffer (0)
6) ends copy mode
7) enters tmux command line mode
8) use this command to save buffer (0) to file ~/out_file, specify with option [ -b buffer-index ] if needed, tmux command list-buffer will show the buffer list

Have fun!

Sources: [ scroll to page buttom, section “Advanced tmux usage” ]

Categories: howto