洛克的猜想

Roco's conjecture

Note: This tip only applies to MyISAM table

Usually when repairing table, mysql will use "repair with keycache" mechanism, it's fast when table is small, but extremely slow when table grows big.

Mysql has another repair mechanism called "repair by sorting", which is 100x faster than keycache mode according to experience.

To tell mysql use sorting mode, you have to specify two variables

  • myisam_max_sort_file_size
    • the max disk size mysql can used to do sorting, set it larger than the row number * key size. If you have 100Million data and key is varchar(32), then this variable must be bigger than 3.2G
  • myisam_sort_buffer_size
    • the max memory size mysql can used to do sorting, set it as large as your machine can afford.

You can set them by set command
  • set global myisam_max_sort_file_size = 3200000000;
  • set global myisam_sort_buffer_size = 128000000;
Note: the max disk size above means the available size of disk which TMPDIR is located

You can get the TMPDIR information by mysql command
  • show variables like "%tmpdir%";
And you can set this parameter by
  • --tmpdir argument when starting mysqld
  • or configure the environment variable TMPDIR when starting mysql

For any further information, please refer to Mysql document.

I had been trying to find a lightweight but powerful email client for a long time, and this became true yesterday.

gnus is a very complicated/powerful tool to read both news and emails, and also there are a lot of different ways to achieve the same goal. Mine is just one of them, but simple.

I assume you already have some basic understanding about emacs before continuing.

Here comes.

0. run command "gnus" to get gnus group buffer
1. Type "^" to enter gnus server mode
2. Type "a" to add a new virtual server

You will be asked for server method, just type "nnimap" for IMAP protocol
Then give a name for this server, whatever you like, for example "dummyimap"

3. Now a new server will be shown up in the server list. Type "e" to edit it like this
(nnimap "dummyimap"
(nnimap-stream ssl) ; enable this if you want to use ssl mode
(nnimap-address "dummyimap.com")
(nnimap-server-port 993))
4. Press "Ctrl+C Ctrl+C" when finished.
5. Navigate to the new server, then press "Enter", it will start to connect to imap server.
6. Fortunately, you will the list of mail folders after authenticated.

This article is only about how to setup gnus with IMAP. If you want more information about how to use gnus, please refer to gnus manual.

Sometimes just a few lines of code may affect performance much.

The following tips are just from my experience. You may already know this :)

1. Implement a log wrapper to log big Object ( assuming that big Object will cost much time to call toString() )

log wrapper like this.
void log.debug(Object o, Object bigObject) {

if (DEBUG >= currentLogLevel) {
log.debug(o + bigObject);
}
}
Comparing to traditional log.debug(o + bigObject), this wrapper will only call bigObject.toString() when log level is lower than DEBUG, saving a lot of time from computing useless toString().


2. Use StringBuffer instead of StringBuilder when constructing new String from Strings.
StringBuilder is known in style like this: Clazz.print("a" + "b" + "c").
Every time, a "+" operation will generate a new String, this will cost more time and space. (String is not mutable)
StringBuffer is known is style like this:
StringBuffer buf = new StringBuffer();
buf.append("a");
buf.append("b");
buf.append("b");
For every method, it will modify the existing object. (StringBuffer is mutable)


3. Use String.indexOf before String.replace
The same reason as before. String.replace will build a new String, to save time and space, we'd better use indexOf to check whether this string has the str to be replaced.
This will gain much more when most time the String.indexOf return -1 (means there is little probability need to call replace).


4. Use ArrayList instead of Vector.
Although Vector is thread-safe, but it will also bring a lot of performance overhead. So usually ArrayList should be better to use instead of Vector, especially when the data is owned internally by single thread.