Did you know GNU parallel?
From time to time I write about some sweet little Linux utilities.
This time let me introduce GNU parallel.
As name suggests, it makes possible to run almost every other command in parallel, on many CPU cores.
Let's give a simple example. Searching for a string in many files. A simple test, on a 2-core box:
$ time bzgrep -w word /u/logs/app*/2012/01/31_app.log.bz2 > word.log real 1m33.492s user 1m25.269s sys 0m8.181s $ time parallel bzgrep -w word ::: /u/logs/app*/2012/01/31_app.log.bz2 > word.log real 0m34.267s user 2m3.112s sys 0m9.193s
For more, read the wonderful list of examples in GNU parallel man page, they speak for themselves.
Of course parallel execution is possible without GNU parallel (with a piece of scripting language, or with xargs)... but this tool is more powerful. See this summary for a list of features and comparison with xargs, pexec and other alternatives.
The great thing about GNU utilities is that they actually still evolve and get better. Every time I see a progress there, it makes me optimistic about the future of open source.
making use of useless things
... like GNU ls (1) single-letter options.
You don't have to know them to make some use of them:
ls -hmm -burrum -burrum -hmmpff
ls -bart -simpson
Useless? Yes, but maybe funny.
Serious note: Official UNIX ls has about 20 option letters. GNU ls has about 40 option letters. What a mess!
Sortowanie w PostgreSQL
Jarek napisał ciekawy artykuł o sortowaniu napisów w PostgreSQL (i nie tylko, w zasadzie rzecz dotyczy localesów w glibc).
windows/unix unicode hell
Task: convert legal UTF8 into Windows native unicode (lilttle-endian, UTF-16).
Solution: UTF8ToUnicode.pl
This way you will identical file as if you opened input with Notepad and saved as "Unicode".
Sekretów zabójcy część druga
bluszcz napisał ciekawy opis kodu linuksowego OOM killera.
Zaciekawiony tematem pokopałem trochę i okazuje się co następuje:
W jednej ze starszych wersji jądra można było go w ogóle wyłączyć.
W 2.6.x z tego co widzę nie ma takiej możliwości.
Za to można wyłączać oom killer per proces!!!
Są sobie albowiem (przynajmniej w 2.6.21 które akurat mam pod ręką) pseudopliki:
/proc/<pid>/oom_score -- tu można podejrzeć aktualny badness score dla procesu,
oraz
/proc/<pid>/oom_adj - tu można sterować wysokością badness score :)
Dozwolone wartości to liczby całkowite z zakresu [-17,+15]. Wysoka wartość to większe prawdopodobieństwo zabicia.
/*
* Adjust the score by oomkilladj.
*/
if (p->oomkilladj) {
if (p->oomkilladj > 0)
points <<= p->oomkilladj;
else
points >>= -(p->oomkilladj);
}
Wartość -17 jest magiczna o tyle że blokuje w ogóle możliwość zabicia procesu przez oom killer.
if (p->oomkilladj == OOM_DISABLE)
continue;
Zatem nasz zabójca ma słaby punkt.
Stosować z umiarem!