Home
%3CLINGO-SUB%20id%3D%22lingo-sub-743860%22%20slang%3D%22en-US%22%3EImprove%20Performance%20of%20Read%20Intensive%20Workloads%20on%20Azure%20DB%20for%20PostgreSQL%20using%20Query%20Caching%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-743860%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EWhen%20building%20cloud%20native%20applications%20using%20managed%20services%2C%20latency%20between%20the%20application%20and%20database%20layer%20can%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eadd%20to%20the%20query%20response%20times%20impacting%20overall%20application%20performance.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EThe%20impact%20is%20visible%20in%20latency%20sensitive%20application%20like%20a%20gaming%20workload%20or%20digital%20payment%20app%20and%20can%20potentially%20impact%20the%20end%20user%20experience%20for%20customers.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EWhile%20leveraging%20managed%20cloud%20services%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bfor%20building%20your%20applications%2C%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bone%20of%20the%20challenge%20(or%20blessing)%20is%2C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ethe%20placement%20of%20application%20VMs%2C%20underlying%20database%20servers%20and%20nodes%20within%20a%20region%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eis%20abstracted%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Efrom%20you%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eso%20if%20the%20application%20server%20and%20database%20node%20are%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Enot%20collocated%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%2C%20the%20network%20latency%20between%20the%20application%20and%20the%20database%20node%20can%20vary.%20As%20a%20result%2C%20if%20you%20are%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Erunning%20your%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ebenchmark%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Btests%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bor%20comparing%20the%20performance%20of%20the%20application%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Erunning%20on-%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Epremises%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Evs%20that%20with%20Azure%20database%20for%20PostgreSQL%20service%2C%20you%20might%20see%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Edifference%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ein%20the%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Equery%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eresponse%20times.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EFor%20data%20modification%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Equeries%2C%20it%20is%20therefore%20recommended%20to%20minimize%20singleton%20transactions%20and%20leverage%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ebatching%20with%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Elarge%20batch%20size%20to%20minimize%20the%20round%20trip%20between%20the%20application%20and%20database%20server.%20For%20query%20performance%2C%20o%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ene%20of%20the%20ways%20to%20improve%20query%20response%20time%20and%20latency%20is%20by%20leveraging%20client-side%20query%20caching%20especially%20when%20you%20are%20designing%20and%20architecting%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Efor%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ea%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bmission%20critical%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eapplication%20with%20low%20latency%20requirements.%20Query%20caching%20is%20one%20of%20the%20common%20techniques%20leveraged%20by%20developers%20to%20improve%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Equery%20response%20times%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E.%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3BThe%20advantages%20of%20client-side%20query%20caching%20are%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22-%22%20data-font%3D%22Calibri%22%20data-listid%3D%222%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%220%22%20data-aria-level%3D%221%22%3E%3CSPAN%20data-contrast%3D%22auto%22%3EIt%20cut%20downs%20the%20network%20latency%20significantly%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ebetween%20the%20application%20and%20database%20layer%20and%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eavoids%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3ESQL%20parsing%2C%20compilation%20and%20execution%20overhead%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ethereby%20improves%20application%20performance%20significantly.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233279%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22-%22%20data-font%3D%22Calibri%22%20data-listid%3D%222%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%220%22%20data-aria-level%3D%221%22%3E%3CSPAN%20data-contrast%3D%22auto%22%3EIt%20reduces%20overhead%20and%20pressure%20on%20the%20database%20server.%20The%20database%20doesn%E2%80%99t%20experience%20memory%20pressure%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ecaused%20by%20caching%20frequently%20accessed%20data%20buffers%20from%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ecomplex%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Equeries%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bjoining%20multiple%20tables%20running%20large%20joins%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233279%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22-%22%20data-font%3D%22Calibri%22%20data-listid%3D%222%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%220%22%20data-aria-level%3D%221%22%3E%3CSPAN%20data-contrast%3D%22auto%22%3EIt%20reduces%20the%20connection%20churn%20on%20the%20database%20server%20which%20also%20adds%20significant%20overhead%20on%20PostgreSQL%20server.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EFor%20more%20details%20on%20connection%20overhead%20with%20PostgreSQL%2C%20read%20our%20blog%20post%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fperformance-best-practices-for-using-azure-database-for-postgresql-connection-pooling%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%20data-contrast%3D%22none%22%3Ehere%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%20data-contrast%3D%22auto%22%3E.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B134233279%26quot%3B%3Atrue%2C%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EThe%20disadvantages%20of%20the%20caching%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eis%2C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ethe%20data%20can%20be%20stale%20and%20needs%20to%20be%20refreshed%20frequently%20so%20for%20OLTP%20or%20highly%20transactional%20workload%20with%20frequent%20data%20modification%2C%20query%20caching%20can%20be%20an%20overhead%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eand%20is%20not%20recommended.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EFor%20read%20heavy%20workloads%2C%20i%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ef%20the%20data%20is%20less%20frequently%20updated%20especially%20for%20data%20warehousing%20or%20ETL%20scenario%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Es%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%2C%20the%20benefits%20of%20query%20caching%20can%20outweigh%20the%20overhead%20of%20maintaining%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ean%20external%20query%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bcache.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3ECurrently%2C%20Redis%20cache%20or%20Memcached%20are%20the%20popular%20external%20query%20caching%20solutions.%20In%20addition%2C%20w%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eith%20PostgreSQL%2C%20there%20are%20community%20developed%20open%20source%20proxy%20solutions%20like%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.pgpool.net%2Fmediawiki%2Findex.php%2FMain_Page%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EPgpool-II%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bor%20proprietary%20solutions%20like%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fblog.heimdalldata.com%2F2019%2F06%2F03%2Fheimdallazure-overview%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CSPAN%20data-contrast%3D%22none%22%3EHeimdall%20Data%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bwhich%20can%20provide%20query%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eresult-set%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ecaching%20to%20improve%20overall%20performance%20of%20the%20application.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3ETo%20give%20you%20some%20stats%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bto%20back%20abovementioned%20theory%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%2C%20we%20ran%20some%20tests%20by%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eprovisioning%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Ba%20Linux%20VM%20on%20Azure%20to%20run%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Epgbench%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bwith%20Pgpool-II%20configured%20for%20query%20caching%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bagainst%20Azure%20Database%20for%20PostgreSQL%20service%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22text-align%3A%20center%3B%22%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20261px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122643i0731D9D8CD32680D%2Fimage-dimensions%2F261x302%3Fv%3D1.0%22%20width%3D%22261%22%20height%3D%22302%22%20alt%3D%22Annotation%202019-07-08%20155346.png%22%20title%3D%22Annotation%202019-07-08%20155346.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1791518237%22%20id%3D%22toc-hId-1791518237%22%3EWith%20No%20Query%20Caching%3C%2FH2%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EL%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eet%E2%80%99s%20first%20assume%20no%20caching.%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%20data-contrast%3D%22auto%22%3EFor%20testing%2C%20we%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Euse%20a%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Esimple%20query%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eand%20an%20aggregation%20query%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eas%20shown%20below.%20In%20all%20cases%2C%20queries%20are%20executed%20over%20an%20already%20existing%20connection%2C%20so%20times%20never%20include%20actual%20connection%20establishment%20time.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3ESimple%20Query%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eexplain%26nbsp%3B(analyze%2C%26nbsp%3Bbuffers%2C%20timing)%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eselect%20*%20from%26nbsp%3Bpgbench_accounts%26nbsp%3Bwhere%20aid%20%3D%20123456%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%20QUERY%20PLAN%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3E------------------------------------------------------------------------------------%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EIndex%20Scan%20using%26nbsp%3Bpgbench_accounts_pkey%26nbsp%3Bon%26nbsp%3Bpgbench_accounts%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EIndex%20Cond%3A%20(aid%20%3D%20123456)%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%E2%80%AF%E2%80%AF%20Buffers%3A%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eshared%20hit%3D4%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EPlanning%20Time%3A%200.082%26nbsp%3Bms%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3EExecution%20Time%3A%200.074%26nbsp%3Bms%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CU%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETime%3A%202.335%26nbsp%3Bms%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EFor%20simple%20queries%2C%20r%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eesponse%20time%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Efor%20simple%20query%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eis%20not%20dominated%20by%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Equery%20execution%20time%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bbut%20by%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Elatency%20between%20client%20and%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eserver%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E.%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3EAggregation%20Query%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eexplain%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E(analyze%2C%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bbuffers%2C%20timing)%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3Eselect%20bid%2C%20sum(abalance)%20from%26nbsp%3Bpgbench_accounts%26nbsp%3Bgroup%20by%20bid%3B%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EPlanning%20time%3A%200.119%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ems%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3EExecution%20time%3A%20274.357%26nbsp%3Bms%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETime%3A%20286.034%26nbsp%3Bms%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--760638724%22%20id%3D%22toc-hId--760638724%22%3EWith%20Query%20Cache%3C%2FH2%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EWith%20query%20caching%20we%20cannot%20only%20save%20query%20execution%20but%20fully%20eliminate%20communication%20from%20client%20to%20the%20PG%20server%20for%20a%20cache%20hit.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20aria-level%3D%223%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-785658106%22%20id%3D%22toc-hId-785658106%22%3ENon-cacheable%20queries%3C%2FH3%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EFor%20queries%20that%20can%E2%80%99t%20be%20cached%2C%20as%20before%2C%20caching%20adds%20some%20overhead%20as%20every%20query%20needs%20to%20be%20analyzed%20and%20checked%20if%20it%20is%20a%20cacheable%20query%20or%20not.%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eexplain%26nbsp%3B(analyze%2C%26nbsp%3Bbuffers%2C%20timing)%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eselect%20*%20from%26nbsp%3Bpgbench_accounts%26nbsp%3Bwhere%20aid%20%3D%20123456%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%E2%80%AF%20QUERY%20PLAN%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3E------------------------------------------------------------------------------------%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EIndex%20Scan%20using%26nbsp%3Bpgbench_accounts_pkey%26nbsp%3Bon%26nbsp%3Bpgbench_accounts%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%E2%80%AF%E2%80%AF%20Index%20Cond%3A%20(aid%20%3D%20123456)%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%E2%80%AF%E2%80%AF%20Buffers%3A%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eshared%20hit%3D4%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EPlanning%20Time%3A%200.078%26nbsp%3Bms%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3EExecution%20Time%3A%200.036%26nbsp%3Bms%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETime%3A%202.616%26nbsp%3Bms%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EWe%20can%20see%20that%20using%26nbsp%3Bquery%26nbsp%3Bcache%20increased%20response%20time%20%3CSTRONG%3Efrom%20~2.3ms%20to%20~2.6ms.%26nbsp%3B%3C%2FSTRONG%3E(the%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Eexplain%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Boption%20makes%20the%20query%20non-cacheable).%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20aria-level%3D%223%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1766498855%22%20id%3D%22toc-hId--1766498855%22%3ECacheable%20queries%3C%2FH3%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EOn%20first%20execution%20of%20a%20cacheable%20query%20overhead%20is%20slightly%20higher%20as%20above%3B%20query%20and%20result%26nbsp%3Bneeds%26nbsp%3Bto%20be%20written%20to%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ecache%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bas%20an%20additional%20step.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eselect%20*%20from%26nbsp%3Bpgbench_accounts%26nbsp%3Bwhere%20aid%20%3D%20123456%3B%3C%2FSTRONG%3E%3CSPAN%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3ETime%3A%202.799%26nbsp%3Bms%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eselect%20bid%2C%20sum(abalance)%20from%26nbsp%3Bpgbench_accounts%26nbsp%3Bgroup%20by%20bid%3B%3C%2FSTRONG%3E%3CSPAN%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3ETime%3A%20291.213%20ms%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3ESubsequent%20calls%20now%20benefit%20from%20query%20cache.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3Eselect%20*%20from%26nbsp%3Bpgbench_accounts%26nbsp%3Bwhere%20aid%20%3D%20123456%3B%3C%2FSTRONG%3E%3CSPAN%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3ETime%3A%200.304%26nbsp%3Bms%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eselect%20bid%2C%20sum(abalance)%20from%26nbsp%3Bpgbench_accounts%26nbsp%3Bgroup%20by%20bid%3B%3C%2FSTRONG%3E%3CSPAN%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3CSTRONG%3ETime%3A%200.284%26nbsp%3Bms%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3EIn%20the%20cached%20scenario%20the%20query%20result%20can%20be%20retrieved%20locally%2C%20without%20having%20to%20send%20the%20query%20to%20the%20remote%20server.%20The%20performance%20improvement%20is%20substantial%20in%20this%20case%2C%20even%20for%20the%20simple%20query.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-172824985%22%20id%3D%22toc-hId-172824985%22%3EConclusion%3C%2FH2%3E%0A%3CP%3E%3CSPAN%20data-contrast%3D%22auto%22%3ESummarizing%20the%20results%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Band%20observations%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%2C%20with%20query%20caching%2C%20the%20query%20response%20time%20is%20improved%20by%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E86%25%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ewith%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%20data-contrast%3D%22auto%22%3Earound%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E~12%25%20degradation%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Ein%20execution%20of%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Enon-cacheable%20queries%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Band%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E~20%25%20degradation%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bin%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3Efirst%20time%20execution%20of%20cacheable%20queries%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%20data-contrast%3D%22auto%22%3E%26nbsp%3Bwhich%20is%20an%20acceptable%20trade-off%20if%20the%20data%20is%20not%20modified%20or%20changed%20frequently.%3C%2FSPAN%3E%3CSPAN%20data-ccp-props%3D%22%7B%26quot%3B201341983%26quot%3B%3A0%2C%26quot%3B335559739%26quot%3B%3A160%2C%26quot%3B335559740%26quot%3B%3A259%7D%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F122644iEA0EE489FE473789%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Annotation%202019-07-08%20160439.png%22%20title%3D%22Annotation%202019-07-08%20160439.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ETo%20conclude%2C%20for%20read%20heavy%20workload%20with%20infrequent%20data%20modification%2C%20query%20caching%20can%20help%20improve%20the%20response%20time%20and%20latency%2C%20significantly%20outweighing%20the%20overhead%20to%20maintain%20external%20cache.%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fwww.pgpool.net%252F%26amp%3Bdata%3D02%257C01%257Cpariks%2540microsoft.com%257C9786cae352104825356108d6fa189013%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C636971380733833764%26amp%3Bsdata%3D2%252ByPbeo5rsNr%252FnejA87wVdxVBrrCKWN2IlKQOeBnGpg%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPgpool%3C%2FA%3E(open%20source)%20and%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fwww.heimdalldata.com%252F%26amp%3Bdata%3D02%257C01%257Cpariks%2540microsoft.com%257C9786cae352104825356108d6fa189013%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C636971380733843768%26amp%3Bsdata%3DCyvdV2ZTH4gERlKH0vNLYD0dBUBkiB6dUCBWT2ZLoBg%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EHeimdall%20Data%3C%2FA%3E(proprietary)%20both%20already%20support%20the%20query%20result%20caching%20by%20intercepting%20connections%20between%20client%2Fapp%20and%20PG%20server%20in%20addition%20to%20connection%20pooling%20and%20load%20balancing%20benefits%20which%20can%20further%20help%20boost%20application%20performance%20with%20read%20replicas.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1915635320%22%20id%3D%22toc-hId-1915635320%22%3ENext%20steps%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FSet-up-Pgpool-II-Query-Caching-with-Azure-Database-for%2Fba-p%2F788005%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EQuickstart%3A%20Query%20caching%20using%20Pgpool%20with%20Azure%20Database%20for%20PostgreSQL%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId--636521641%22%20id%3D%22toc-hId--636521641%22%3EReferences%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22http%3A%2F%2Fwww.pgpool.net%2Fdocs%2Flatest%2Fen%2Fhtml%2Finstallation.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EInstallation%20for%20Pgpool-II%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-read-replicas%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERead%20Replicas%20in%20Azure%20Database%20for%20PostgreSQL%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fblog.heimdalldata.com%2F2019%2F06%2F03%2Fheimdallazure-overview%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EEnhance%20your%20Application%20and%20Data%20interaction%20with%20Heimdall%20Database%20Proxy%20in%20Azure%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FCreate-a-master-server-and-read-replicas-in-Azure-Database-for%2Fba-p%2F691262%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ECreate%20a%20master%20server%20and%20read%20replicas%20in%20Azure%20Database%20for%20PostgreSQL%20using%20the%20Azure%20CLI%3C%2FA%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EBenjamin%20Satzger%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EPrincipal%20Software%20Engineer%2C%20Microsoft%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EParikshit%20Savjani%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ESenior%20Program%20Manager%2C%20Microsoft%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-743860%22%20slang%3D%22en-US%22%3E%3CP%3EImprove%20Performance%20of%20Read%20Intensive%20Workloads%20on%20Azure%20DB%20for%20PostgreSQL%20using%20Query%20Caching%3C%2FP%3E%3C%2FLINGO-TEASER%3E

 

When building cloud native applications using managed services, latency between the application and database layer can add to the query response times impacting overall application performance. The impact is visible in latency sensitive application like a gaming workload or digital payment app and can potentially impact the end user experience for customers. 

 

While leveraging managed cloud services for building your applications, one of the challenge (or blessing) is, the placement of application VMs, underlying database servers and nodes within a region is abstracted from you so if the application server and database node are not collocated, the network latency between the application and the database node can vary. As a result, if you are running your benchmark tests or comparing the performance of the application running on-premises vs that with Azure database for PostgreSQL service, you might see difference in the query response times. 

 

For data modification queries, it is therefore recommended to minimize singleton transactions and leverage batching with large batch size to minimize the round trip between the application and database server. For query performance, one of the ways to improve query response time and latency is by leveraging client-side query caching especially when you are designing and architecting for a mission critical application with low latency requirements. Query caching is one of the common techniques leveraged by developers to improve query response times. The advantages of client-side query caching are 

 

  • It cut downs the network latency significantly between the application and database layer and avoids SQL parsing, compilation and execution overhead thereby improves application performance significantly. 
  • It reduces overhead and pressure on the database server. The database doesn’t experience memory pressure caused by caching frequently accessed data buffers from complex queries joining multiple tables running large joins 
  • It reduces the connection churn on the database server which also adds significant overhead on PostgreSQL server. For more details on connection overhead with PostgreSQL, read our blog post here. 

The disadvantages of the caching is, the data can be stale and needs to be refreshed frequently so for OLTP or highly transactional workload with frequent data modification, query caching can be an overhead and is not recommended. For read heavy workloads, if the data is less frequently updated especially for data warehousing or ETL scenarios, the benefits of query caching can outweigh the overhead of maintaining an external query cache.  

 

Currently, Redis cache or Memcached are the popular external query caching solutions. In addition, with PostgreSQL, there are community developed open source proxy solutions like Pgpool-II or proprietary solutions like Heimdall Data which can provide query result-set caching to improve overall performance of the application.  

 

To give you some stats to back abovementioned theory, we ran some tests by provisioning a Linux VM on Azure to run pgbench with Pgpool-II configured for query caching against Azure Database for PostgreSQL service. 

 

Annotation 2019-07-08 155346.png

With No Query Caching

Let’s first assume no caching. For testing, we use a simple query and an aggregation query as shown below. In all cases, queries are executed over an already existing connection, so times never include actual connection establishment time. 

 

Simple Query 

explain (analyze, buffers, timing) 
select * from pgbench_accounts where aid = 123456; 

                                   QUERY PLAN  

------------------------------------------------------------------------------------ 

Index Scan using pgbench_accounts_pkey on pgbench_accounts 
   Index Cond: (aid = 123456) 
   Buffers: shared hit=4 
Planning Time: 0.082 ms 
Execution Time: 0.074 ms 

Time: 2.335 ms 

 

For simple queries, response time for simple query is not dominated by query execution time but by latency between client and server .  

 

Aggregation Query 

explain (analyze, buffers, timing) 
select bid, sum(abalance) from pgbench_accounts group by bid; 

Planning time: 0.119 ms 
Execution time: 274.357 ms 

Time: 286.034 ms 

 

With Query Cache

With query caching we cannot only save query execution but fully eliminate communication from client to the PG server for a cache hit. 

 

Non-cacheable queries

For queries that can’t be cached, as before, caching adds some overhead as every query needs to be analyzed and checked if it is a cacheable query or not.  

 

explain (analyze, buffers, timing) 
select * from pgbench_accounts where aid = 123456; 

                                   QUERY PLAN  

------------------------------------------------------------------------------------ 

Index Scan using pgbench_accounts_pkey on pgbench_accounts 
   Index Cond: (aid = 123456) 
   Buffers: shared hit=4 
Planning Time: 0.078 ms 
Execution Time: 0.036 ms 

Time: 2.616 ms 

 

We can see that using query cache increased response time from ~2.3ms to ~2.6ms. (the explain option makes the query non-cacheable).  

 

Cacheable queries

On first execution of a cacheable query overhead is slightly higher as above; query and result needs to be written to cache as an additional step. 

 

select * from pgbench_accounts where aid = 123456; 
Time: 2.799 ms 

 

select bid, sum(abalance) from pgbench_accounts group by bid; 
Time: 291.213 ms

 

Subsequent calls now benefit from query cache. 

 
select * from pgbench_accounts where aid = 123456; 
Time: 0.304 ms 

 

select bid, sum(abalance) from pgbench_accounts group by bid; 
Time: 0.284 ms 

 

In the cached scenario the query result can be retrieved locally, without having to send the query to the remote server. The performance improvement is substantial in this case, even for the simple query. 

 

Conclusion

Summarizing the results and observations, with query caching, the query response time is improved by 86% with around ~12% degradation in execution of non-cacheable queries and ~20% degradation in first time execution of cacheable queries which is an acceptable trade-off if the data is not modified or changed frequently. 

Annotation 2019-07-08 160439.png

To conclude, for read heavy workload with infrequent data modification, query caching can help improve the response time and latency, significantly outweighing the overhead to maintain external cache. Pgpool (open source) and Heimdall Data (proprietary) both already support the query result caching by intercepting connections between client/app and PG server in addition to connection pooling and load balancing benefits which can further help boost application performance with read replicas.

 

Next steps

References

 

Benjamin Satzger

Principal Software Engineer, Microsoft

 

Parikshit Savjani

Senior Program Manager, Microsoft