Friday, September 27, 2013

python readline

# sudo aptitude install build-essential libreadline6-dev

#cd Python-..

# sed 's/#readline/readline/' Modules/Setup.dist > file.tmp && mv file.tmp Modules/Setup.dist

#./configure
#make
#make install

Friday, September 20, 2013

Nagios Indicator

Gnome indicator for nagios

It adds icon indicator to gnome panel.
This applet automatically check your nagios server and notify about all problems using popup messages.


https://github.com/volodymyrko/nagios_indicator

Thursday, June 27, 2013

mysql: find InnoDB table size

How to find Innodb tables size?

"show table status" command doesn't show separated Innodb tables size, it showes total InnoDB data size. So we can use INFORMATION_SCHEMA for finding size of each InnoDB table.

for example, try  find 10 biggest InnoDB tables:

#mysql -A


mysql> use INFORMATION_SCHEMA
mysql> SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE, TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH, CREATE_TIME, UPDATE_TIME FROM TABLES WHERE ENGINE='InnoDB' ORDER BY DATA_LENGTH DESC limit 10;



using  INFORMATION_SCHEMA you can find data_length, index_length and other useful information

Wednesday, May 29, 2013

mysql: How find fragmented MySQL tables

#mysql

> use information_schema

> select ENGINE, TABLE_NAME,Round( DATA_LENGTH/1024/1024) as data_length , round(INDEX_LENGTH/1024/1024) as index_length, round(DATA_FREE/ 1024/1024) as data_free from information_schema.tables where DATA_FREE > 0;




The "You must to know" answer

first at all you must to understand that Mysql tables get fragmented when update a row, so it's a normal situation. When a table is created, lets say imported using a dump with data, all rows are stored with no fragmentation in many fixed size pages. When you update a variable length row, the page containing this row is divided in two or more pages to store the changes, and these new two(or more) pages contains blank spaces filling the unused space.

This does not impact in your performance, unless of course the fragmentation growth too much. What is too much fragmentation, well let's see the query you're looking for:

select ENGINE, TABLE_NAME,Round( DATA_LENGTH/1024/1024) as data_length , round(INDEX_LENGTH/1024/1024) as index_length, round(DATA_FREE/ 1024/1024) as data_free from information_schema.tables where DATA_FREE > 0;

The DATA_LENGTH and INDEX_LENGTH are the space your data and indexes are using, and DATA_FREE is the total amount of bytes unused in all the table pages (fragmentation).

Here's an example of real production table

| ENGINE | TABLE_NAME | data_length | index_length | data_free |
| InnoDB | comments | 896 | 316 | 5 |

In this case we have a Table using (896 + 316) = 1212 MB, and have data a free space of 5 MB. This means a "ratio of fragmentation" of:

5/1212 = 0.0041

...Which is a really low "fragmentation ratio".

I've been working with tables with a ratio near 0.2 (meaning 20% of blank spaces) and never notice a slow down on queries, even if I optimize the table, the performance is the same. But apply a optimize table on a 800MB table takes a lot of time and blocks the table for several minutes, impracticable on production.

So, if you consider what you win in performance and the time wasted in optimize a table, I prefer NOT OPTIMIZE.

If you think it's better for storage, see your ratio and see how much space can you save when optimize. It's usually not too much, so I prefer NOT OPTIMIZE.

And if you optimize, the next update will create blank spaces by splitting a page in two or more. But it's faster to update a fragmented table than a not fragmented one, because if the table is fragmented an update on a row not necessarily will split a page.

I hope this help you.



http://serverfault.com/questions/202000/how-find-and-fix-fragmented-mysql-tables
http://dba.stackexchange.com/questions/16341/how-do-you-remove-fragmentation-from-innodb-tables

Monday, May 27, 2013

Add virtualhost name to apache logfile

If you have many ServerAlias in some apache VirtualHost and You want to see name of virtualhost in lofgile add  %{host}i to logformat direcive,

for example,

LogFormat "%h %{host}i %l %u %D %T %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

php performance

strace huge lstat try:
php.ini


; ...
; Determines the size of the realpath cache to be used by PHP. This value should
; be increased on systems where PHP opens many files to reflect the quantity of
; the file operations performed.
realpath_cache_size=1M

; Duration of time, in seconds for which to cache realpath information for a given
; file or directory. For systems with rarely changing files, consider increasing this
; value.
realpath_cache_ttl=300
; ...

Friday, March 29, 2013

bash: як замінити стрічку у файлі

маємо файл file.txt

# cat file.txt
this is simple text file
here is 1-st line
4-th line
some 3-rd line
end of file



Наприклад, треба замінити стрічку яка містить  "4-th line" . Зробити це можна за допомогою sed-у:


# cat file.txt | sed '/4-th line/c 2-nd line'
this is simple text file
here is 1-st line
2-nd line
some 3-rd line
end of file



Але треба памятати, що sed міняє сам файл у такому випадку. Тому, якщо треба змнити файл, можна зробити шось таке:


# cat file.txt | sed '/4-th line/c 2-nd line' > tmp.txt && mv tmp.txt file.txt


таким вийшов  новий файл


# cat file.txt
this is simple text file
here is 1-st line
2-nd line
some 3-rd line
end of file