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-19-2008, 10:46 AM
Gaetano Mendola
 
Posts: n/a
Default shared_buffers performance

Hi all,
I started to do some performance tests (using pgbench) in order to
estimate the DRBD impact on our servers, my plan was to perform some
benchmarks without DRBD in order to compare the same benchmark with
DRBD.
I didn't perform yet the benchmark with DRBD and I'm already facing
something I can not explain (I performed at the moment only reads test).

I'm using postgres 8.2.3 on Red Hat compiled with GCC 3.4.6.

I'm using pgbench with scaling factor with a range [1:500], my server
has 4 cores so I'm trying with 16 client and 4000 transaction per
client: pgbench -t 4000 -c 16 -S db_perf. I did 3 session using 3 different
values of shared_buffers: 64MB, 256MB, 512MB and my server has 2GB.

The following graph reports the results:

http://img84.imageshack.us/my.php?image=totalid7.png

as you can see using 64MB as value for shared_buffers I'm obtaining better
results. Is this something expected or I'm looking in the wrong direction?
I'm going to perform same tests without using the -S option in pgbench but
being a time expensive operation I would like to ear your opinion first.

Regards
Gaetano Mendola





--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 10:46 AM
Gregory Stark
 
Posts: n/a
Default Re: shared_buffers performance

"Gaetano Mendola" <mendola@gmail.com> writes:

> The following graph reports the results:
>
> http://img84.imageshack.us/my.php?image=totalid7.png


That's a *fascinating* graph.

It seems there are basically three domains.

The small domain where the database fits in shared buffers -- though actually
this domain seems to hold until the accounts table is about 1G so maybe it's
more that the *indexes* fit in memory. Here larger shared buffers do clearly
win.

The transition domain where performance drops dramatically as the database
starts to not fit in shared buffers but does still fit in filesystem cache.
Here every megabyte stolen from the filesystem cache makes a *huge*
difference. At a scale factor of 120 or so you're talking about a factor of 4
between each of the shared buffer sizes.

The large domain where the database doesn't fit in filesystem cache. Here it
doesn't make a large difference but the more buffers duplicated between
postgres and the filesystem cache the lower the overall cache effectiveness.

If we used something like either mmap or directio to avoid the double
buffering we would be able to squeeze these into a single curve, as well as
push the dropoff slightly to the right. In theory.

In practice it would depend on the OS's ability to handle page faults
efficiently in the mmap case, and our ability to do read-ahead and cache
management in the directio case. And it would be a huge increase in complexity
for Postgres and a push into a direction which isn't our "core competency". We
might find that while in theory it should perform better our code just can't
keep up with Linux's and it doesn't.

I'm curious about the total database size as a for each of the scaling factors
as well as the total of the index sizes. And how much memory Linux says is
being used for filesystem buffers.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's PostGIS support!

--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 10:46 AM
Richard Huxton
 
Posts: n/a
Default Re: shared_buffers performance

Gregory Stark wrote:
> "Gaetano Mendola" <mendola@gmail.com> writes:
>
>> The following graph reports the results:
>>
>> http://img84.imageshack.us/my.php?image=totalid7.png

>
> That's a *fascinating* graph.


It is, isn't it? Thanks Gaetano.

> It seems there are basically three domains.
>
> The small domain where the database fits in shared buffers -- though actually
> this domain seems to hold until the accounts table is about 1G so maybe it's
> more that the *indexes* fit in memory. Here larger shared buffers do clearly
> win.


I think this is actually in two parts - you can see it clearly on the
red trace (64MB), less so on the green (256MB) and not at all on the
blue (512MB). Presumably the left-hand steeper straight-line decline
starts with the working-set in shared-buffers, and the "knee" is where
we're down to just indexes in shared-buffers.

With the blue I guess you just get the first part, because by the time
you're overflowing shared-buffers, you've not got enough disk-cache to
take up the slack for you.

I wonder what difference 8.3 makes to this?

--
Richard Huxton
Archonet Ltd

--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 10:46 AM
Greg Smith
 
Posts: n/a
Default Re: shared_buffers performance

On Mon, 14 Apr 2008, Gaetano Mendola wrote:

> I'm using postgres 8.2.3 on Red Hat compiled with GCC 3.4.6.


8.2.3 has a performance bug that impacts how accurate pgbench results are;
you really should be using a later version.

> http://img84.imageshack.us/my.php?image=totalid7.png
> as you can see using 64MB as value for shared_buffers I'm obtaining
> better results.


I'm assuming you've read my scaling article at
http://www.westnet.com/~gsmith/conte...ch-scaling.htm
since you're using the graph template I suggest there.

If you look carefully at your results, you are getting better results for
higher shared_buffers values in the cases where performance is memory
bound (the lower scale numbers). Things reverse so that more buffers
gives worse performance only when your scale >100. I wouldn't conclude
too much from that. The pgbench select test is doing a low-level
operation that doesn't benefit as much from having more memory available
to PostgreSQL instead of the OS as a real-world workload will.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-19-2008, 10:46 AM
Greg Smith
 
Posts: n/a
Default Re: shared_buffers performance

On Mon, 14 Apr 2008, Gregory Stark wrote:

> I'm curious about the total database size as a for each of the scaling factors
> as well as the total of the index sizes.


That's all in a table at
http://www.westnet.com/~gsmith/conte...ch-scaling.htm

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-19-2008, 10:46 AM
Tom Lane
 
Posts: n/a
Default Re: shared_buffers performance

Gregory Stark <stark@enterprisedb.com> writes:
> The transition domain where performance drops dramatically as the database
> starts to not fit in shared buffers but does still fit in filesystem cache.


It looks to me like the knee comes where the DB no longer fits in
filesystem cache. What's interesting is that there seems to be no
synergy at all between shared_buffers and the filesystem cache.
Ideally, very hot pages would stay in shared buffers and drop out of the
kernel cache, allowing you to use a database approximating all-of-RAM
before you hit the performance wall. It's clear that in this example
that's not happening, or at least that only a small part of shared
buffers isn't getting duplicated in filesystem cache.

Of course, that's because pgbench reads a randomly-chosen row of
"accounts" in each transaction, so that there's exactly zero locality
of access. A more realistic workload would probably have a Zipfian
distribution of account number touches, and might look a little better
on this type of test.

regards, tom lane

--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-19-2008, 10:46 AM
Gregory Stark
 
Posts: n/a
Default Re: shared_buffers performance

"Tom Lane" <tgl@sss.pgh.pa.us> writes:

> Gregory Stark <stark@enterprisedb.com> writes:
>> The transition domain where performance drops dramatically as the database
>> starts to not fit in shared buffers but does still fit in filesystem cache.

>
> It looks to me like the knee comes where the DB no longer fits in
> filesystem cache.


That does seem to make a lot more sense. I think I misread the units of the
size of the accounts table. Reading it again it seems to be in the 1.5G-2G
range for the transition which with indexes and other tables might be starting
to stress the filesystem cache -- though it still seems a little low.

I think if I squint I can see another dropoff at the very small scaling
numbers. That must be the point where the database is comparable to the shared
buffers size. Except then I would expect the green and blue curves to be
pushed to the right a bit rather than just havin a shallower slope.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's On-Demand Production Tuning

--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-19-2008, 10:46 AM
Greg Smith
 
Posts: n/a
Default Re: shared_buffers performance

On Mon, 14 Apr 2008, Tom Lane wrote:

> Ideally, very hot pages would stay in shared buffers and drop out of the
> kernel cache, allowing you to use a database approximating all-of-RAM
> before you hit the performance wall.


With "pgbench -S", the main hot pages that get elevated usage counts and
cling persistantly to shared buffers are those holding data from the
primary key on the accounts table.

Here's an example of what the buffer cache actually has after running
"pgbench -S -c 8 -t 10000 pgbench" on a system with shared_buffers=256MB
and a total of 2GB of RAM. Database scale is 100, so there's
approximately 1.5GB worth of database, mainly a 1.3GB accounts table and
171MB of primary key on accounts:

relname |buffered| buffers % | % of rel
accounts | 306 MB | 65.3 | 24.7
accounts pkey | 160 MB | 34.1 | 93.2

relname | buffers | usage
accounts | 10223 | 0
accounts | 25910 | 1
accounts | 2825 | 2
accounts | 214 | 3
accounts | 14 | 4
accounts pkey | 2173 | 0
accounts pkey | 5392 | 1
accounts pkey | 5086 | 2
accounts pkey | 3747 | 3
accounts pkey | 2296 | 4
accounts pkey | 1756 | 5

This example and the queries to produce that summary are all from the
"Inside the PostgreSQL Buffer Cache" talk on my web page.

For this simple workload, if you can fit the main primary key in shared
buffers that helps, but making that too large takes away memory that could
be more usefully given to the OS to manage. The fact that you can start
to suffer from double-buffering (where the data is in the OS filesystem
cache and shared_buffers) when making shared_buffers too large on a
benchmark workload is interesting. But I'd suggest considering the real
application, rather than drawing a conclusion about shared_buffers sizing
based just on that phenomenon.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-19-2008, 10:46 AM
Gaetano Mendola
 
Posts: n/a
Default Re: shared_buffers performance

Greg Smith wrote:
> On Mon, 14 Apr 2008, Gaetano Mendola wrote:
>
>> I'm using postgres 8.2.3 on Red Hat compiled with GCC 3.4.6.

>
> 8.2.3 has a performance bug that impacts how accurate pgbench results
> are; you really should be using a later version.


Thank you, I will give it a shot and performe some tests to see if
they change a lot, in case I will repeat the entire benchmarks.

Regards
Gaetano Mendola
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-19-2008, 10:46 AM
Gaetano Mendola
 
Posts: n/a
Default Re: shared_buffers performance

Gaetano Mendola wrote:
> Hi all,
> I started to do some performance tests (using pgbench) in order to
> estimate the DRBD impact on our servers, my plan was to perform some
> benchmarks without DRBD in order to compare the same benchmark with
> DRBD.
> I didn't perform yet the benchmark with DRBD and I'm already facing
> something I can not explain (I performed at the moment only reads test).
>
> I'm using postgres 8.2.3 on Red Hat compiled with GCC 3.4.6.
>
> I'm using pgbench with scaling factor with a range [1:500], my server
> has 4 cores so I'm trying with 16 client and 4000 transaction per
> client: pgbench -t 4000 -c 16 -S db_perf. I did 3 session using 3 different
> values of shared_buffers: 64MB, 256MB, 512MB and my server has 2GB.
>
> The following graph reports the results:
>
> http://img84.imageshack.us/my.php?image=totalid7.png
>
> as you can see using 64MB as value for shared_buffers I'm obtaining better
> results. Is this something expected or I'm looking in the wrong direction?
> I'm going to perform same tests without using the -S option in pgbench but
> being a time expensive operation I would like to ear your opinion first.


I have complete today the other benchmarks using pgbench in write mode as well,
and the following graph resumes the results:

http://img440.imageshack.us/my.php?image=totalwbn0.png

what I can say here the trend is the opposite seen on the read only mode as
increasing the shared_buffers increases the TPS.

I still didn't upgrade to 8.2.7 as suggested by Greg Smith because I would like
to compare the results obtained till now with the new one (simulations running
while I write) using postgres on a "DRBD partition"; sure as soon the current
tests terminate I will upgrade postgres.

If you have any suggestions on what you would like to see/know, just let me know.

Regards
Gaetano Mendola



--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

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



All times are GMT. The time now is 05:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759