Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 11:04 AM
Marinos J. Yannikos
 
Posts: n/a
Default GiST indexes and concurrency (tsearch2)

Hi,

according to
http://www.postgresql.org/docs/8.0/i...mitations.html ,
concurrent access to GiST indexes isn't possible at the moment. I
haven't read the thesis mentioned there, but I presume that concurrent
read access is also impossible. Is there any workaround for this, esp.
if the index is usually only read and not written to?

It seems to be a big problem with tsearch2, when multiple clients are
hammering the db (we have a quad opteron box here that stays 75% idle
despite an apachebench with concurrency 10 stressing the php script that
uses tsearch2, with practically no disk accesses)

Regards,
Marinos
--
Dipl.-Ing. Marinos Yannikos, CEO
Preisvergleich Internet Services AG
Obere Donaustraße 63/2, A-1020 Wien
Tel./Fax: (+431) 5811609-52/-55

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 11:04 AM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

> It seems to be a big problem with tsearch2, when multiple clients are
> hammering the db (we have a quad opteron box here that stays 75% idle
> despite an apachebench with concurrency 10 stressing the php script that
> uses tsearch2, with practically no disk accesses)


Concurrency with READs is fine - but you can only have one WRITE going
at once.

Chris

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 11:04 AM
Oleg Bartunov
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

On Thu, 3 Feb 2005, Marinos J. Yannikos wrote:

> Hi,
>
> according to http://www.postgresql.org/docs/8.0/i...mitations.html
> , concurrent access to GiST indexes isn't possible at the moment. I haven't
> read the thesis mentioned there, but I presume that concurrent read access is
> also impossible. Is there any workaround for this, esp. if the index is
> usually only read and not written to?


there are should no problem with READ access.

>
> It seems to be a big problem with tsearch2, when multiple clients are
> hammering the db (we have a quad opteron box here that stays 75% idle despite
> an apachebench with concurrency 10 stressing the php script that uses
> tsearch2, with practically no disk accesses)


I'm willing to see some details: version, query, explain analyze.




>
> Regards,
> Marinos
>


Regards,
Oleg
__________________________________________________ ___________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 11:04 AM
Tom Lane
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

"Marinos J. Yannikos" <mjy@geizhals.at> writes:
> I can't seem to find out where the bottleneck is, but it doesn't seem to
> be CPU or disk. "top" shows that postgres processes are frequently in
> this state:


> 6701 postgres 16 0 204m 58m 56m S 9.3 0.2 0:06.96 semtimedo
> ^^^^^^^^^


What's the platform exactly (hardware and OS)?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-18-2008, 11:04 AM
Oleg Bartunov
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

Marinos,

what if you construct "apachebench & Co" free script and see if
the issue still exists. There are could be many issues doesn't
connected to postgresql and tsearch2.

Oleg

On Thu, 3 Feb 2005, Marinos J. Yannikos wrote:

> Oleg Bartunov wrote:
>> On Thu, 3 Feb 2005, Marinos J. Yannikos wrote:
>>> concurrent access to GiST indexes isn't possible at the moment. I [...]

>>
>> there are should no problem with READ access.

>
> OK, thanks everyone (perhaps it would make sense to clarify this in the
> manual).
>
>> I'm willing to see some details: version, query, explain analyze.

>
> 8.0.0
>
> Query while the box is idle:
>
> explain analyze select count(*) from fr_offer o, fr_merchant m where idxfti
> @@ to_tsquery('ranz & mc') and eur >= 70 and m.m_id=o.m_id;
>
> Aggregate (cost=2197.48..2197.48 rows=1 width=0) (actual time=88.052..88.054
> rows=1 loops=1)
> -> Merge Join (cost=2157.42..2196.32 rows=461 width=0) (actual
> time=88.012..88.033 rows=3 loops=1)
> Merge Cond: ("outer".m_id = "inner".m_id)
> -> Index Scan using fr_merchant_pkey on fr_merchant m
> (cost=0.00..29.97 rows=810 width=4) (actual time=0.041..1.233 rows=523
> loops=1)
> -> Sort (cost=2157.42..2158.57 rows=461 width=4) (actual
> time=85.779..85.783 rows=3 loops=1)
> Sort Key: o.m_id
> -> Index Scan using idxfti_idx on fr_offer o
> (cost=0.00..2137.02 rows=461 width=4) (actual time=77.957..85.754 rows=3
> loops=1)
> Index Cond: (idxfti @@ '\'ranz\' & \'mc\''::tsquery)
> Filter: (eur >= 70::double precision)
>
> Total runtime: 88.131 ms
>
> now, while using apachebench (-c10), "top" says this:
>
> Cpu0 : 15.3% us, 10.0% sy, 0.0% ni, 74.7% id, 0.0% wa, 0.0% hi, 0.0% si
> Cpu1 : 13.3% us, 11.6% sy, 0.0% ni, 75.1% id, 0.0% wa, 0.0% hi, 0.0% si
> Cpu2 : 16.9% us, 9.6% sy, 0.0% ni, 73.4% id, 0.0% wa, 0.0% hi, 0.0% si
> Cpu3 : 18.7% us, 14.0% sy, 0.0% ni, 67.0% id, 0.0% wa, 0.0% hi, 0.3% si
>
> (this is with shared_buffers = 2000; a larger setting makes almost no
> difference for overall performance: although according to "top" system time
> goes to ~0 and user time to ~25%, the system still stays 70-75% idle)
>
> vmstat:
>
> r b swpd free buff cache si so bi bo in cs us sy id
> wa
> 2 0 0 8654316 64908 4177136 0 0 56 35 279 286 5 1 94
> 0
> 2 0 0 8646188 64908 4177136 0 0 0 0 1156 2982 15 10 75
> 0
> 2 0 0 8658412 64908 4177136 0 0 0 0 1358 3098 19 11 70
> 0
> 1 0 0 8646508 64908 4177136 0 0 0 104 1145 2070 13 12 75
> 0
>
> so the script's execution speed is apparently not limited by the CPUs.
>
> The query execution times go up like this while apachebench is running (and
> the system is 75% idle):
>
> Aggregate (cost=2197.48..2197.48 rows=1 width=0) (actual
> time=952.661..952.663 rows=1 loops=1)
> -> Merge Join (cost=2157.42..2196.32 rows=461 width=0) (actual
> time=952.621..952.641 rows=3 loops=1)
> Merge Cond: ("outer".m_id = "inner".m_id)
> -> Index Scan using fr_merchant_pkey on fr_merchant m
> (cost=0.00..29.97 rows=810 width=4) (actual time=2.078..3.338 rows=523
> loops=1)
> -> Sort (cost=2157.42..2158.57 rows=461 width=4) (actual
> time=948.345..948.348 rows=3 loops=1)
> Sort Key: o.m_id
> -> Index Scan using idxfti_idx on fr_offer o
> (cost=0.00..2137.02 rows=461 width=4) (actual time=875.643..948.301 rows=3
> loops=1)
> Index Cond: (idxfti @@ '\'ranz\' & \'mc\''::tsquery)
> Filter: (eur >= 70::double precision)
> Total runtime: 952.764 ms
>
> I can't seem to find out where the bottleneck is, but it doesn't seem to be
> CPU or disk. "top" shows that postgres processes are frequently in this
> state:
>
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ WCHAN COMMAND
> 6701 postgres 16 0 204m 58m 56m S 9.3 0.2 0:06.96 semtimedo
> ^^^^^^^^^
> postmaste
>
> Any hints are appreciated...
>
> Regards,
> Marinos
>


Regards,
Oleg
__________________________________________________ ___________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-18-2008, 11:04 AM
Tom Lane
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

"Marinos J. Yannikos" <mjy@geizhals.at> writes:
> according to
> http://www.postgresql.org/docs/8.0/i...mitations.html ,
> concurrent access to GiST indexes isn't possible at the moment. I
> haven't read the thesis mentioned there, but I presume that concurrent
> read access is also impossible.


You presume wrong ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-18-2008, 11:04 AM
Tom Lane
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

Marinos Yannikos <mjy@geizhals.at> writes:
> This is really baffling me, it looks like a kernel issue of some sort
> (I'm only guessing though). I found this old posting:
> http://archives.postgresql.org/pgsql...2/msg00836.php - is
> this still applicable?


That seems to be an early report of what we now recognize as the
"context swap storm" problem, and no we don't have a solution yet.
I'm not completely convinced that you're seeing the same thing,
but if you're seeing a whole lot of semops then it could well be.

I set up a test case consisting of two backends running the same
tsearch2 query over and over --- nothing fancy, just one of the ones
from the tsearch2 regression test:
SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
I used gdb to set breakpoints at PGSemaphoreLock and PGSemaphoreTryLock,
which are the only two functions that can possibly block on a semop
call. On a single-processor machine, I saw maybe one hit every couple
of seconds, all coming from contention for the BufMgrLock or sometimes
the LockMgrLock. So unless I've missed something, there's not anything
in tsearch2 or gist per se that is causing lock conflicts. You said
you're testing a quad-processor machine, so it could be that you're
seeing the same lock contention issues that we've been trying to figure
out for the past year ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-18-2008, 11:05 AM
Marinos Yannikos
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

Oleg Bartunov schrieb:
> Marinos,
>
> what if you construct "apachebench & Co" free script and see if
> the issue still exists. There are could be many issues doesn't
> connected to postgresql and tsearch2.
>


Some more things I tried:
- data directory on ramdisk (tmpfs) - no effect
- database connections either over Unix domain sockets or TCP - no effect
- CLUSTER on gist index - approx. 20% faster queries, but CPU usage
still hovers around 25% (75% idle)
- preemptible kernel - no effect

This is really baffling me, it looks like a kernel issue of some sort
(I'm only guessing though). I found this old posting:
http://archives.postgresql.org/pgsql...2/msg00836.php - is
this still applicable? I don't see an unusually high number of context
switches, but the processes seem to be spending some time in
"semtimedop" (even though the TAS assembly macros are definetely being
compiled-in).

If you are interested, I can probably provide an account on one of our
identically configured boxes by Monday afternoon (GMT+1) with the same
database and benchmarking utility.

Regards,
Marinos

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-18-2008, 11:05 AM
Tom Lane
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

Marinos Yannikos <mjy@geizhals.at> writes:
> Some more things I tried:


You might try the attached patch (which I just applied to HEAD).
It cuts down the number of acquisitions of the BufMgrLock by merging
adjacent bufmgr calls during a GIST index search. I'm not hugely
hopeful that this will help, since I did something similar to btree
last spring without much improvement for context swap storms involving
btree searches ... but it seems worth trying.

regards, tom lane

*** src/backend/access/gist/gistget.c.orig Fri Dec 31 17:45:27 2004
--- src/backend/access/gist/gistget.c Sat Feb 5 14:19:52 2005
***************
*** 60,69 ****
BlockNumber blk;
IndexTuple it;

b = ReadBuffer(s->indexRelation, GISTP_ROOT);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);
- so = (GISTScanOpaque) s->opaque;

for (;
{
--- 60,70 ----
BlockNumber blk;
IndexTuple it;

+ so = (GISTScanOpaque) s->opaque;
+
b = ReadBuffer(s->indexRelation, GISTP_ROOT);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);

for (;
{
***************
*** 75,86 ****

while (n < FirstOffsetNumber || n > maxoff)
{
! ReleaseBuffer(b);
! if (so->s_stack == NULL)
return false;

! stk = so->s_stack;
! b = ReadBuffer(s->indexRelation, stk->gs_blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);
maxoff = PageGetMaxOffsetNumber(p);
--- 76,89 ----

while (n < FirstOffsetNumber || n > maxoff)
{
! stk = so->s_stack;
! if (stk == NULL)
! {
! ReleaseBuffer(b);
return false;
+ }

! b = ReleaseAndReadBuffer(b, s->indexRelation, stk->gs_blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);
maxoff = PageGetMaxOffsetNumber(p);
***************
*** 89,94 ****
--- 92,98 ----
n = OffsetNumberPrev(stk->gs_child);
else
n = OffsetNumberNext(stk->gs_child);
+
so->s_stack = stk->gs_parent;
pfree(stk);

***************
*** 116,123 ****
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
blk = ItemPointerGetBlockNumber(&(it->t_tid));

! ReleaseBuffer(b);
! b = ReadBuffer(s->indexRelation, blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);
}
--- 120,126 ----
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
blk = ItemPointerGetBlockNumber(&(it->t_tid));

! b = ReleaseAndReadBuffer(b, s->indexRelation, blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);
}
***************
*** 137,142 ****
--- 140,147 ----
BlockNumber blk;
IndexTuple it;

+ so = (GISTScanOpaque) s->opaque;
+
blk = ItemPointerGetBlockNumber(&(s->currentItemData));
n = ItemPointerGetOffsetNumber(&(s->currentItemData));

***************
*** 148,154 ****
b = ReadBuffer(s->indexRelation, blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);
- so = (GISTScanOpaque) s->opaque;

for (;
{
--- 153,158 ----
***************
*** 157,176 ****

while (n < FirstOffsetNumber || n > maxoff)
{
! ReleaseBuffer(b);
! if (so->s_stack == NULL)
return false;

! stk = so->s_stack;
! b = ReadBuffer(s->indexRelation, stk->gs_blk);
p = BufferGetPage(b);
- maxoff = PageGetMaxOffsetNumber(p);
po = (GISTPageOpaque) PageGetSpecialPointer(p);

if (ScanDirectionIsBackward(dir))
n = OffsetNumberPrev(stk->gs_child);
else
n = OffsetNumberNext(stk->gs_child);
so->s_stack = stk->gs_parent;
pfree(stk);

--- 161,183 ----

while (n < FirstOffsetNumber || n > maxoff)
{
! stk = so->s_stack;
! if (stk == NULL)
! {
! ReleaseBuffer(b);
return false;
+ }

! b = ReleaseAndReadBuffer(b, s->indexRelation, stk->gs_blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);
+ maxoff = PageGetMaxOffsetNumber(p);

if (ScanDirectionIsBackward(dir))
n = OffsetNumberPrev(stk->gs_child);
else
n = OffsetNumberNext(stk->gs_child);
+
so->s_stack = stk->gs_parent;
pfree(stk);

***************
*** 198,205 ****
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
blk = ItemPointerGetBlockNumber(&(it->t_tid));

! ReleaseBuffer(b);
! b = ReadBuffer(s->indexRelation, blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);

--- 205,211 ----
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
blk = ItemPointerGetBlockNumber(&(it->t_tid));

! b = ReleaseAndReadBuffer(b, s->indexRelation, blk);
p = BufferGetPage(b);
po = (GISTPageOpaque) PageGetSpecialPointer(p);


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-18-2008, 11:06 AM
Marinos J. Yannikos
 
Posts: n/a
Default Re: GiST indexes and concurrency (tsearch2)

Tom Lane wrote:
> You might try the attached patch (which I just applied to HEAD).
> It cuts down the number of acquisitions of the BufMgrLock by merging
> adjacent bufmgr calls during a GIST index search. [...]


Thanks - I applied it successfully against 8.0.0, but it didn't seem to
have a noticeable effect. I'm still seeing more or less exactly 25% CPU
usage by postgres processes and identical query times (measured with the
Perl script I posted earlier).

Regards,
Marinos
--
Dipl.-Ing. Marinos Yannikos, CEO
Preisvergleich Internet Services AG
Obere Donaustrasse 63, A-1020 Wien
Tel./Fax: (+431) 5811609-52/-55

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:49 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490