Tuesday, October 15, 2013

watching queries per second (vmstat style) on MySQL

Good trick!

mysqladmin ext -ri 1 |grep -i -e queries -e \-
view raw vmsqlstat.sh hosted with ❤ by GitHub
+-----------------------------------+--------------+
+-----------------------------------+--------------+
| Qcache_queries_in_cache | 5282 |
| Queries | 669070336 |
| Slow_queries | 2950563 |
+-----------------------------------+--------------+
+-----------------------------------+--------------+
+-----------------------------------+--------------+
| Innodb_data_pending_fsyncs | -1 |
| Qcache_free_memory | -2440 |
| Qcache_queries_in_cache | 1 |
| Queries | 211 |
| Slow_queries | 0 |
+-----------------------------------+--------------+
+-----------------------------------+--------------+
+-----------------------------------+--------------+
| Qcache_queries_in_cache | 0 |
| Queries | 177 |
| Slow_queries | 0 |
+-----------------------------------+--------------+
+-----------------------------------+--------------+
+-----------------------------------+--------------+
| Innodb_data_pending_fsyncs | -1 |
| Innodb_os_log_pending_fsyncs | -1 |
| Qcache_queries_in_cache | 0 |
| Queries | 133 |
| Slow_queries | 0 |
+-----------------------------------+--------------+
+-----------------------------------+--------------+
+-----------------------------------+--------------+
| Open_files | -8 |
| Qcache_queries_in_cache | 0 |
| Queries | 687 |
| Slow_queries | 0 |
+-----------------------------------+--------------+
+-----------------------------------+--------------+
+-----------------------------------+--------------+
| Open_files | -2 |
| Qcache_queries_in_cache | -13 |
| Qcache_total_blocks | -12 |
| Queries | 544 |
| Slow_queries | 0 |
+-----------------------------------+--------------+
+-----------------------------------+--------------+
+-----------------------------------+--------------+
view raw zoutput hosted with ❤ by GitHub
:D

Wednesday, October 9, 2013

Compiling a .cpp source with OpenCV libs in MacOSX/Ubuntu 13.04

Yes!.... the way to run cpp is different between OS:
# MacOS X 10.7.x
# You need opencv is installed (macports)
g++ -ggdb `pkg-config --cflags opencv` `pkg-config --libs opencv` header.cpp header2.cpp program.cpp -o program
view raw macosx hosted with ❤ by GitHub
# Ubuntu 13.04 / Mint 15
# opencv from source because package version doesn't have nonfree modules separated (SURF/SIFT)
# and you can have problems (install pkg-config too)
g++ -o program program.cpp `pkg-config opencv --cflags --libs`
view raw ubuntu hosted with ❤ by GitHub
;)

Tuesday, October 1, 2013

massive-kill for mysql sleep connections (concept)

Mmmm.... It is not a good trick.... but it could be useful: https://gist.github.com/vicendominguez/8820342
#This is a bullshit but... i will kill all the sleep connections which sleeping time starting with 8
for a in `echo "show processlist" |mysql --user=root --password=tete coredb |egrep 'Sleep[[:space:]]+8[[:digit:]]+' |awk '{ print $1 }'`; do echo "KILL $a" | mysql --user=root --password=tete coredb; done
view raw gistfile1.sh hosted with ❤ by GitHub
Update: Perhaps this is a better way (Mysql procedure): https://gist.github.com/datacharmer/5946490
-- SQL
drop procedure if exists purge_slow_queries;
drop procedure if exists purge_idle_connections;
drop event if exists auto_purge_slow_queries;
drop event if exists auto_purge_idle_connections;
delimiter //
create procedure purge_idle_connections()
deterministic
begin
declare done boolean default false;
declare max_time int default coalesce(@max_kill_time, 200);
declare pid bigint;
declare c cursor for
SELECT id
FROM information_schema.processlist
WHERE command in ('Sleep')
AND time > max_time;
declare continue handler for not found
set done = true;
open c;
set @q_kill = 'KILL ?';
prepare q_kill from @q_kill;
PURGELOOP: loop
fetch c into pid;
if done then
leave PURGELOOP;
end if;
set @pid = pid;
execute q_kill using @pid;
end loop;
deallocate prepare q_kill;
end//
create procedure purge_slow_queries()
deterministic
begin
declare done boolean default false;
declare max_time int default coalesce(@max_kill_time, 200);
declare pid bigint;
declare c cursor for
SELECT id
FROM information_schema.processlist
WHERE state in ('executing')
AND time > max_time;
declare continue handler for not found
set done = true;
open c;
set @q_kill = 'KILL ?';
prepare q_kill from @q_kill;
PURGELOOP: loop
fetch c into pid;
if done then
leave PURGELOOP;
end if;
set @pid = pid;
execute q_kill using @pid;
end loop;
deallocate prepare q_kill;
end//
delimiter ;
create event auto_purge_idle_connections
on schedule every 10 second
do call purge_idle_connections();
create event auto_purge_slow_queries
on schedule every 10 second
do call purge_slow_queries();
:S