Subject Poor performance retrieving/storing BLOBs columns on linux
Author marrtins_dqdp
Problem: Selecting or inserting BLOBs is very slow on Linux machine.
Query: SELECT * FROM PAYMENT_IMPORT;

Query: SELECT list,of,non,blob,fields FROM PAYMENT_IMPORT;
No performance degradation

I found similar issue here:
http://tech.groups.yahoo.com/group/firebird-support/message/71320

But it didn`t help me much :(

Here is a sample table:
CREATE DOMAIN TEXT AS Blob sub_type 1 COLLATE UTF8;
CREATE TABLE PAYMENT_IMPORT(
ID Integer NOT NULL,
PRICE MONEY DEFAULT 0.00,
CURRENCY CURRENCY_ID DEFAULT 'LVL',
CURRENCY_RATE Double precision,
PAYMENT_DATE Timestamp,
NOTES TEXT,
CSV_DATA TEXT,
PRIMARY KEY (ID)
);

NOTES,CSV_DATA - BLOB columns. Tried dropping them and recreating as
Blob sub_type 1 (CHARACTER SET NONE) - no changes.

Database info: Windows: WI-V2.1.0.17798
---------------------
ODS Version: 11.1
Page size: 16384
Pages: 808
Size on disk: 12.63MB
Page buffers: 2048
Read only: false
Dialect: 3
Default character set: UTF8
Sweep interval: 20000
Forced writes: yes

Database info (all SuperServers): Linux 2.6.14: Windows:
LI-V2.1.1.17910 NPTL (tried also different versions: V2.1.1.17910
non-NTPL, LI-V2.1.0.17798 both NTPL and non-NPTL). I tried also
compile V2.1.1.17910 - no change.
---------------------
ODS Version: 11.1
Page size: 16384
Pages: 910
Size on disk: 14.22MB
Page buffers: 2048
Read only: false
Dialect: 3
Default character set: UTF8
Sweep interval: 20000
Forced writes: yes

Data set: identical, 1117 rows on both platforms

Windows 2000 machine: Dual core AMD 3800+, 2gb ram
Windows fbclient: WI-V6.3.0.17798 Firebird 2.1

Linux machine: 2x1ghz Xeon, 1gb ram, kernel 2.6.14.4 SMP with NPTL support
Linux fbclient: LI-V6.3.1.17910 Firebird 2.1

Query statistics:

Windows 127.0.0.1:/path/to/db with FlameRobin:
----------------
*2264* fetches,0 marks, 0 reads, 0 writes, 0 inserts, 0 updates, 0
deletes, 37 index, 856 seq.
Delta memory: 8100 bytes.
Execute time: *00:00:00*

Linux local, isql (output to file or /dev/null - no matter)
----------------
*11215* fetches, 0 reads, 0 writes
Current memory = 35048772
Delta memory = -28
Max memory = 35519708
Cpu = 0.00 sec
Buffers = 2048
Elapsed time= *33.15 sec*

Local php, remote flamerobin (both gave very similar statistics):
-----------------------------
*5572* fetches, 0 marks, 0 reads, 0 writes, 0 inserts, 0 updates, 0
deletes,0 index, 856 seq.
Delta memory: 7340 bytes.
Execute time: *00:00:08.*

When selection query contains only one BLOB field, execution time
drops twice *00:00:04.*

Tried to put database on different disks - no change.

Here is system statistics while executing query on linux machine:
04:22:58 AM CPU %user %nice %system %iowait %steal
%idle
04:22:59 AM all 2.94 0.00 49.51 0.00 0.00
47.55
04:23:00 AM all 3.47 0.00 48.51 0.00 0.00
48.02
04:23:01 AM all 3.96 0.00 49.50 0.00 0.00
46.53
04:23:02 AM all 3.96 0.00 49.01 0.00 0.00
47.03
04:23:03 AM all 2.97 0.00 48.51 0.00 0.00
48.51
04:23:04 AM all 3.96 0.00 50.50 0.00 0.00
45.54
04:23:05 AM all 0.99 0.00 52.97 0.00 0.00
46.04
04:23:06 AM all 3.96 0.00 50.00 0.00 0.00
46.04
04:23:07 AM all 1.98 0.00 50.00 0.00 0.00
48.02
04:23:08 AM all 22.28 0.00 50.00 0.00 0.00
27.72
Average: all 5.04 0.00 49.85 0.00 0.00
45.10

As we can see, there is lots of system processing and idling and just
5% user processing. It`s kinda strange (Don't know for sure. Am I wrong?).

I did strace on fbserver while executing query, which gave me a *lot* of:

select(10, [9], NULL, NULL, NULL) = 1 (in [9])
recv(9, "\0\0\0\'\0\0\0\4\0\0\0008\0\0\0\0\0\0\0\1\0\0\0\220\0\0"...,
8192, 0) = 28
futex(0x8403dac, FUTEX_WAKE, 1) = 1
futex(0xb7aa3e1c, 0x4 /* FUTEX_??? */, 1) = 1
futex(0xb7aa3e00, FUTEX_WAKE, 1) = 1
futex(0x840b738, FUTEX_WAKE, 1) = 1
time(NULL) = 1214012117
select(10, [0 1 6 7 8 9], NULL, NULL, {60, 0}) = 1 (in [9], left {60, 0})

select(10, [9], NULL, NULL, NULL) = 1 (in [9])
recv(9, "\0\0\0$\0\0\0\4\0\0@\0\0\0\0\0", 8192, 0) = 16
futex(0x8403dac, FUTEX_WAKE, 1) = 1
futex(0xb7aa5918, 0x4 /* FUTEX_??? */, 1) = 1
futex(0xb7aa58fc, FUTEX_WAKE, 1) = 1
futex(0x840b738, FUTEX_WAKE, 1) = 1
time(NULL) = 1214012117
select(10, [0 1 6 7 8 9], NULL, NULL, {60, 0}) = 1 (in [9], left {59,
990000})

etc. etc.
here come huge amounts of above

Any ideas?

Thank you very much!