Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 06:53 AM
Benjamin Krajmalnik
 
Posts: n/a
Default Re: Performance question

Unfortunately, the application doing the logging is not written by me,
so I have to play with the deck of cards which I am dealt.
The developer stated that he uses connection pooling, but apparently the
pg odbc driver does not support it, since I can see a new connection
being made for each statement execution.
I have asked him to see if he can create one connection and maintain it
- we'll see.

I have another scenario to try out, whereby instead of making a stored
procedure call via ODBC I will insert the parameters of the SP call into
a table via simple insert statements. If I see significant improvements
(I am not holding my breath), I will use that route and run a background
peocess on the server to issue the SP calls off of that recordset.

> -----Original Message-----
> From: Jim C. Nasby [mailto:decibel@decibel.org]
> Sent: Monday, December 04, 2006 8:25 PM
> To: Benjamin Krajmalnik
> Cc: pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] Performance question
>
> Please cc the list so others can learn and help.
>
> Yes, if ODBC is tearing the connection down after every call,
> performance *WILL* suck. Setup some kind of persistent connection.
> Better yet, don't make lots of tiny calls to the database if
> you can avoid it.
>
> On Mon, Dec 04, 2006 at 06:28:03PM -0700, Benjamin Krajmalnik wrote:
> > Hi Jim,
> >
> > Apples to apples (as best as I can tell).
> > The test procedure was as follows:
> >
> > I captured the SQL statements which call the stored procedures from
> > our monitoring box to a file.
> > I copied the file to the FreeBSD data server.
> > Executed psql, and pumped the file to it through \i filename.
> > Execution speed for the code in question was sub 10 seconds.
> > Running the query directly via ODBC is taking about 60 ms.
> >
> > The numbers I just stated above are after I removed the

> code which was
> > accessing the one partitioned table where the constraint

> exclusion was
> > not taking place (more on that later). This code happened to be
> > updating a daily aggregate - so each SP call was selecting the test
> > record for the day and aggregating data. I ended up adding

> a few more
> > fields to a records which keeps some data in arrays for

> quick access
> > to generate our graphs, and now I run a scheduled task at midnight
> > which takes the previous days aggregates and creates our snapshot
> > records (which we use for historical trending of up to 24 months).
> > This process now takes about 5 seconds, whereas running it

> through the
> > stored procedure it was adding almost 200 miliseconds to

> the execution time).
> > I assume this was caused by the fact that there was a

> select - and the
> > execution planner was not isolating to the single

> partitioned table,
> > followed by either an insert or another update.
> > The new code is much more efficient and loads the db much

> less, so it
> > will be the preferred method.
> > Right now the datra path between the monitoring appliacne

> and the data
> > server is 100Mbit. We are moving it to Gig tonight - so at least I
> > hope I will realize some speed advantages. I have been

> monitoring the
> > switch, and the actual throughput is only 150kbit/sec, so I do not
> > have a data throughput bpttlenecg, but rather I suspect

> latencies in
> > the ODBC connection.
> >
> > The item I found interesting is that the statement duration

> was much
> > longer.
> > What I am thinking is that when running through psql, it is using a
> > local pipe.
> > When running through ODBC, each stored procedure call is creating a
> > connection and then disconnecting, so it has added a huge

> overhead. I
> > think the duration is including the time it is taking to
> > connect/authenticate disconnect/teardown.
> >
> > Thanks for the tip on the constraint exclusion.
> > I need to go back and see how we are querying it for the

> reports, and
> > will adjust it accordingly.
> > Does it make a difference if it is timestamp or timestamp without
> > timezone?
> >
> >
> > > -----Original Message-----
> > > From: Jim Nasby [mailto:decibel@decibel.org]
> > > Sent: Monday, December 04, 2006 5:53 PM
> > > To: Benjamin Krajmalnik
> > > Cc: pgsql-admin@postgresql.org
> > > Subject: Re: [ADMIN] Performance question
> > >
> > > Are you sure you're doing an apples-apples comparison? Is

> the load
> > > on both machines the same, or does production have extra stuff
> > > running?
> > > Have you tried your original test again in the same setup without
> > > ODBC to eliminate that possibility? (or redone your original test
> > > with ODBC).
> > >
> > > As for the constraint exclusion, try changing the query so that
> > > '2006-12-01' is cast to a timestamp (or change the constraints so
> > > that you're constraining dates... the check constraints should
> > > really match the type of the underlying table).
> > >
> > > On Dec 1, 2006, at 9:18 PM, Benjamin Krajmalnik wrote:
> > >
> > > > I am battling a performance issue and was wondering if
> > > someone could
> > > > help. PostgreSQL 8.1.5, FreeBSD.
> > > >
> > > > I have a very intense stored procedure which performs real time
> > > > aggregation of data.
> > > >
> > > > I captured the stored procedure calls from a production

> system and
> > > > pumped them through psql, logging duration.
> > > > The stored procedure ran at about 30ms per stored

> procedure call -
> > > > which
> > > > was significantly faster than the previous production system.
> > > > Based on
> > > > these results, I was extremely optimistic and migrated

> to the new
> > > > server.
> > > >
> > > > Now that we turned up the new server, the stored procedure
> > > is taking
> > > > over 250ms.
> > > > These are the execution times as recorded by enable

> "all" logging.
> > > >
> > > > The only difference is that when I pumped the data in the test
> > > > environment, I pumped it by reading the script via psql,
> > > whereas the
> > > > current system is calling the stored procedure via ODBC

> through a
> > > > 100Mbit ethernet connection.
> > > >
> > > > I cannot explain the difference between the 2

> scenarios. Does the
> > > > duration include the overhead of the ODBC layer?
> > > >
> > > > Now, the second part that was troubling relates to the

> execution
> > > > planner.
> > > >
> > > >
> > > > Two of the tables in which data is being entered are

> partitioned
> > > > tables.
> > > > Data is being routed to the partition by using rules. Each
> > > partition
> > > > has a check constraint on a date range. Constraint

> exclusion is on.
> > > >
> > > > The first partitioned table is very simple, and the stored
> > > procedure
> > > > simply inserts a record for each test which is executed. These
> > > > are later used by a procedure running in the background which
> > > calculates
> > > > statistical data.
> > > >
> > > > My problem is with the second partitioned table. As part of my
> > > > troubleshooting, I omitted the code from the stored procedure
> > > > which accesses this data. In this table, I attempt to retrieve
> > > > the daily record for a specific test. If it is not

> found, after
> > > > aggregating data I insert it. If the record already

> exists, data
> > > > is aggregated and the record is updated.
> > > >
> > > > The key is composed of a date field (monthdate) and an

> int4 field
> > > > (kstestsysid).
> > > > The check constraints are of the form of:
> > > >
> > > > ALTER TABLE tblkssnapshot12
> > > > ADD CONSTRAINT tblkssnapshot12_chk CHECK (monthdate >=
> > > '2006-12-01
> > > > 00:00:00'::timestamp without time zone AND monthdate <

> '2007-01-01
> > > > 00:00:00'::timestamp without time zone);
> > > >
> > > > I ran a sample query which would be issued by the

> stored procedure
> > > > with the explain option.
> > > > The query was:
> > > >
> > > > select monthdate, kstestssysid from tblkssnapshotdaily
> > > where monthdate
> > > > = '2006-12-01' and kstestssysid = 3143
> > > >
> > > > The explain is as follows:
> > > >
> > > > select monthdate, kstestssysid from tblkssnapshotdaily
> > > where monthdate
> > > > = '2006-12-01' and kstestssysid = 3143 Result

> (cost=0.00..122.49
> > > > rows=25 width=8)
> > > > -> Append (cost=0.00..122.49 rows=25 width=8)
> > > > -> Index Scan using

> tblkssnapshotdaily_idx_monthtest on
> > > > tblkssnapshotdaily (cost=0.00..3.52 rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot01_idx_monthtest on
> > > > tblkssnapshot01 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot02_idx_monthtest on
> > > > tblkssnapshot02 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot03_idx_monthtest on
> > > > tblkssnapshot03 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot04_idx_monthtest on
> > > > tblkssnapshot04 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot05_idx_monthtest on
> > > > tblkssnapshot05 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot06_idx_monthtest on
> > > > tblkssnapshot06 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot07_idx_monthtest on
> > > > tblkssnapshot07 tblkssnapshotdaily (cost=0.00..5.94

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot08_idx_monthtest on
> > > > tblkssnapshot08 tblkssnapshotdaily (cost=0.00..4.73

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot09_idx_monthtest on
> > > > tblkssnapshot09 tblkssnapshotdaily (cost=0.00..5.56

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot10_idx_monthtest on
> > > > tblkssnapshot10 tblkssnapshotdaily (cost=0.00..5.75

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot11_idx_monthtest on
> > > > tblkssnapshot11 tblkssnapshotdaily (cost=0.00..5.81

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot12_idx_monthtest on
> > > > tblkssnapshot12 tblkssnapshotdaily (cost=0.00..4.33

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot13_idx_monthtest on
> > > > tblkssnapshot13 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot14_idx_monthtest on
> > > > tblkssnapshot14 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot15_idx_monthtest on
> > > > tblkssnapshot15 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot16_idx_monthtest on
> > > > tblkssnapshot16 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot17_idx_monthtest on
> > > > tblkssnapshot17 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot18_idx_monthtest on
> > > > tblkssnapshot18 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot19_idx_monthtest on
> > > > tblkssnapshot19 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot20_idx_monthtest on
> > > > tblkssnapshot20 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot21_idx_monthtest on
> > > > tblkssnapshot21 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot22_idx_monthtest on
> > > > tblkssnapshot22 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot23_idx_monthtest on
> > > > tblkssnapshot23 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > > -> Index Scan using tblkssnapshot24_idx_monthtest on
> > > > tblkssnapshot24 tblkssnapshotdaily (cost=0.00..4.83

> rows=1 width=8)
> > > > Index Cond: ((monthdate = '2006-12-01'::date) AND
> > > > (kstestssysid = 3143))
> > > >
> > > > If constraint exclusion is on, why are index scans taking
> > > place on all
> > > > of the tables and not only on the only partitioned table
> > > for which the
> > > > constraint exists?
> > > >
> > > > I went to a partitioned table thinking this would improve
> > > performance
> > > > from the previous schema in which all of the data was in the
> > > > parent table, but the end result was significantly slower
> > > > performance (by orders of magnitude).
> > > >
> > > >
> > > >
> > > > ---------------------------(end of
> > > > broadcast)---------------------------
> > > > TIP 5: don't forget to increase your free space map settings
> > > >
> > >
> > > --
> > > Jim Nasby jim@nasby.net
> > > EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)
> > >
> > >
> > >

> >

>
> --
> Jim C. Nasby, Database Architect decibel@decibel.org
> Give your computer some brain candy! www.distributed.net Team #1828
>
> Windows: "Where do you want to go today?"
> Linux: "Where do you want to go tomorrow?"
> FreeBSD: "Are you guys coming, or what?"
>


---------------------------(end of broadcast)---------------------------
TIP 4: 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
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 10:10 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 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 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964