SlideShare una empresa de Scribd logo
1 de 16
PostgreSQL Query Cache
         “pqc”

                March/1/2011

     Satoshi Nagayasu
 Uptime Technologies, LLC.



Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Overview
•   By caching result responses from backend, a query cache daemon
    (`pqcd’) makes query response faster “extremely” (x10~x100).
    –   Delegates queries in front of the backend, like a proxy.
    –   Waits connections on the different port (9999 by default).
    –   Intercepts and caches SELECT query results. (Query Cache)
    –   Manages lifecycle of the query cache.

                                                                             Server side
                                      Direct execution

          PostgreSQL                                                                     PostgreSQL
             client                                                                      backend(s)
                             Execution                      pqcd
                                with
                             the query
                               cache                   Cache Memory


                    Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Tech Specs
•   Supports simple query executions, and prepared statements.
     – Supports V3 protocol only. (V2 is not supported)

•   Supports “Active cache mode”
     – All SELECT query results would be stored in the query cache.
     – User specified query would not be cached.

•   Supports “Passive cache mode”
     – All SELECT query results would NOT be cached.
     – Only user specified SELECT queries would be cached.
     – And/or queries which took longer execution time than the user-specified
       duration, would be cached. (Not implemented yet)

•   Supports cache invalidation (expiration or refreshing)
     – By using the cache expiration timeout.
     – By using “hint” with SELECT statements.
     – By using “hint” to expire all query cache. (Not implemented yet)

                     Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
The Query Cache Flow Overview
•   After `pqcd’ receives a SELECT statement, if some result is
    available in the query cache, `pqcd’ returns the result from the query
    cache. If not available, it relays the query to the backend.

              Receive a query
               from frontend


                  Is cache              No
                 available?
                        Yes
                Not expired            No              Invalidate                         Forward the query
                   yet?                                the cache                             to backend
                          Yes
               Fetch a result                                                              Retreive a result
             from query cache                                                             from the backend

                                                                                             Store a result
            Send to the frontend
                                                                                          in the query cache


                     Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Implementation
•   Using KVS (Memcached) to hold the query cache.
    – “libmemcached” as a memcached client library for C.
    – A SQL statement as a key, and response messages as a value.
•   `pqcd’, a query cache daemon, is implemented as a derivative of
    pgpool.
    – Un-used feature (code) removed, and several “hook” routines added.
                                                                     Server side


      PostgreSQL                                                                        PostgreSQL
         client                                         pqcd                            backend(s)

                                                 Hook routines
                                                libmemcached


                                                  Memcached

                   Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Deployment
•   Required packages
     – libevent 1.4.14b (required by memcached)
     – memcached 1.4.5
     – libmemcached 0.43

•   How to install
     –   automake
     –   ./configure --prefix=$PREFIX
     –   make
     –   sudo make install
     –   cd $PREFIX/etc
     –   cp pqcd_hba.conf.sample pqcd_hba.conf

•   Starting pqcd
     – $PREFIX/bin/pqcd

•   Stopping pqcd
     – $PREFIX/bin/pqcd stop

                     Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Deployment (with RPMs)
•   Required RPM
     –   uqc-libevent-1.4.14b-1.i386.rpm
     –   uqc-memcached-1.4.5-1.i386.rpm
     –   uqc-libmemcached-0.43-1.i386.rpm
     –   uqc-querycache-20110223-1.i386.rpm

•   Configuration files
     – /opt/uptime/querycache/etc/pqcd.conf
     – /opt/uptime/querycache/etc/pqcd_hba.conf

•   Starting pqcd
     – /opt/uptime/querycache/bin/pqcd

•   Stopping pqcd
     – /opt/uptime/querycache/bin/pqcd stop



                     Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Configurations
•   `pqcd.conf’ may be configured as you need. (in $PREFIX/etc)

•   memcached_bin
    – A path name to Memcached executable. (default is
      “/opt/uptime/querycache/bin/memcached”)


•   query_cache_mode
    – The query cache mode. “active” or “passive”. (default is “active”)


•   query_cache_expiration
    – The timeout value for query cache expiration (in seconds, default is 30)




                    Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Cache hints
•   Add as a comment at the beginning of SELECT statements
     – /* cache:refresh */SELECT * FROM …
     – <slash> <asterrisk> <space> <hint> <space> <asterisk> <slash>


•   cache:on (default in Active cache mode)
     – Looks at the cache first. If not found, then executes on the backend, and puts the
       result into the cache.
•   cache:off (default in Passive cache mode)
     – Doesn’t look at the cache. Execute on the backend first, and doesn’t put the
       result into the cache.
•   cache:refresh
     – Doesn’t look at the cache first. Executes on the backend, and puts the result into
       the cache.
•   cache:expire
     – Invalidates query cache for specified statement. (Not implemented yet)
•   cache:expireall
     – Invalidates all query cache. (Not implemented yet)

                       Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Examples




Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Query execution and the cache




                           A regular scan
                           takes >400ms.




                                    2nd execution completes
                                    in 0.5ms with the cache.




   Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
A hint to handle the cache.



                                     Add a hint to disable
                                      the query cache.


                                    Longer time.



                   Without a hint,
               the query cache again.




 Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Record updates and the cache


                                            Delete all records.




                    Still an old value left
                         in the cache.




  Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Refreshing the query cache




                                     Add a hint to
                                  refresh the cache.




                The value in the
                cache refreshed.

                           With hitting
                           the cache.



 Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
TODO
•   To Do
    – Handle a transaction state correctly on “Z (ready for query)” response.
    – Make expandable cache values for >8192bytes.
    – Make enable to handle cache key with >250 charactors. (limitation from
      Memcached)
    – Automatic query caching by watching duration time under the Passive cache
      mode.
    – Run benchmarks!

•   Done
    – PreparedStatement.
    – Cache hints.
    – Rename the binary to ‘pqcd’ in Makefile
    – Start/stop Memcached from pqcd.
    – Invalidation query cache by timeout. (query_cache_expiration option)
    – Completes a pgbench run.
    – Remove V2 protocol code. (prevent to be conneced with V2 at startup)
    – `memcached_bin’ option added in pqcd.conf.
    – Put a connected database name into the cache key.
    – Remove un-used code (replication, master-slave, dual server under connection
      pooling) – “Keep it simple, stupid!”
    – Make it public as an opensource software!

                     Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
Contact:
Uptime Technologies, LLC.
E-Mail: contact@uptime.jp
Web: http://www.uptime.jp/

                   Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.

Más contenido relacionado

La actualidad más candente

MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)Jean-François Gagné
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]MongoDB
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsAlexander Korotkov
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance TuningMaven Logix
 
Análise de Performance do MySQL e MariaDB
Análise de Performance do MySQL e MariaDBAnálise de Performance do MySQL e MariaDB
Análise de Performance do MySQL e MariaDBSaveincloud
 
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...Mydbops
 
Auditing and Monitoring PostgreSQL/EPAS
Auditing and Monitoring PostgreSQL/EPASAuditing and Monitoring PostgreSQL/EPAS
Auditing and Monitoring PostgreSQL/EPASEDB
 
MySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to HaveMySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to HaveSveta Smirnova
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDBMongoDB
 
Deep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesDeep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesIbrar Ahmed
 
patroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deploymentpatroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deploymenthyeongchae lee
 
Transparent Data Encryption in PostgreSQL and Integration with Key Management...
Transparent Data Encryption in PostgreSQL and Integration with Key Management...Transparent Data Encryption in PostgreSQL and Integration with Key Management...
Transparent Data Encryption in PostgreSQL and Integration with Key Management...Masahiko Sawada
 
[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google CloudPgDay.Seoul
 
MySQL GTID Concepts, Implementation and troubleshooting
MySQL GTID Concepts, Implementation and troubleshooting MySQL GTID Concepts, Implementation and troubleshooting
MySQL GTID Concepts, Implementation and troubleshooting Mydbops
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Deploying PostgreSQL on Kubernetes
Deploying PostgreSQL on KubernetesDeploying PostgreSQL on Kubernetes
Deploying PostgreSQL on KubernetesJimmy Angelakos
 
엘라스틱서치 실무 가이드_202204.pdf
엘라스틱서치 실무 가이드_202204.pdf엘라스틱서치 실무 가이드_202204.pdf
엘라스틱서치 실무 가이드_202204.pdf한 경만
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldJignesh Shah
 

La actualidad más candente (20)

MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance Tuning
 
Análise de Performance do MySQL e MariaDB
Análise de Performance do MySQL e MariaDBAnálise de Performance do MySQL e MariaDB
Análise de Performance do MySQL e MariaDB
 
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
PostgreSQL 15 and its Major Features -(Aakash M - Mydbops) - Mydbops Opensour...
 
Auditing and Monitoring PostgreSQL/EPAS
Auditing and Monitoring PostgreSQL/EPASAuditing and Monitoring PostgreSQL/EPAS
Auditing and Monitoring PostgreSQL/EPAS
 
MySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to HaveMySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to Have
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
 
Deep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesDeep dive to PostgreSQL Indexes
Deep dive to PostgreSQL Indexes
 
patroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deploymentpatroni-based citrus high availability environment deployment
patroni-based citrus high availability environment deployment
 
Transparent Data Encryption in PostgreSQL and Integration with Key Management...
Transparent Data Encryption in PostgreSQL and Integration with Key Management...Transparent Data Encryption in PostgreSQL and Integration with Key Management...
Transparent Data Encryption in PostgreSQL and Integration with Key Management...
 
[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud
 
MySQL GTID Concepts, Implementation and troubleshooting
MySQL GTID Concepts, Implementation and troubleshooting MySQL GTID Concepts, Implementation and troubleshooting
MySQL GTID Concepts, Implementation and troubleshooting
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Deploying PostgreSQL on Kubernetes
Deploying PostgreSQL on KubernetesDeploying PostgreSQL on Kubernetes
Deploying PostgreSQL on Kubernetes
 
엘라스틱서치 실무 가이드_202204.pdf
엘라스틱서치 실무 가이드_202204.pdf엘라스틱서치 실무 가이드_202204.pdf
엘라스틱서치 실무 가이드_202204.pdf
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 

Similar a PostgreSQL Query Cache - "pqc"

OOW09 Ebs Tuning Final
OOW09 Ebs Tuning FinalOOW09 Ebs Tuning Final
OOW09 Ebs Tuning Finaljucaab
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for WindowsFord AntiTrust
 
DevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on KubernetesDevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on KubernetesDinakar Guniguntala
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsMaarten Smeets
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesBruno Borges
 
Apache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning PlatformApache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning PlatformWangda Tan
 
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EECON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EEMasoud Kalali
 
Ceph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer SpotlightCeph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer SpotlightRed_Hat_Storage
 
Ceph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer SpotlightCeph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer SpotlightColleen Corrice
 
Resume_CQ_Edward
Resume_CQ_EdwardResume_CQ_Edward
Resume_CQ_Edwardcaiqi wang
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningGraham Dumpleton
 
PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + MemcachedFord AntiTrust
 
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...elliando dias
 
Improving PHP Application Performance with APC
Improving PHP Application Performance with APCImproving PHP Application Performance with APC
Improving PHP Application Performance with APCvortexau
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsConcentric Sky
 
[Hic2011] using hadoop lucene-solr-for-large-scale-search by systex
[Hic2011] using hadoop lucene-solr-for-large-scale-search by systex[Hic2011] using hadoop lucene-solr-for-large-scale-search by systex
[Hic2011] using hadoop lucene-solr-for-large-scale-search by systexJames Chen
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 

Similar a PostgreSQL Query Cache - "pqc" (20)

OOW09 Ebs Tuning Final
OOW09 Ebs Tuning FinalOOW09 Ebs Tuning Final
OOW09 Ebs Tuning Final
 
ESIGate dev meeting #4 21-11-2013
ESIGate dev meeting #4 21-11-2013ESIGate dev meeting #4 21-11-2013
ESIGate dev meeting #4 21-11-2013
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
 
DevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on KubernetesDevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on Kubernetes
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck Threads
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
Apache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning PlatformApache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning Platform
 
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EECON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
 
Ceph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer SpotlightCeph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer Spotlight
 
Ceph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer SpotlightCeph Deployment at Target: Customer Spotlight
Ceph Deployment at Target: Customer Spotlight
 
cosbench-openstack.pdf
cosbench-openstack.pdfcosbench-openstack.pdf
cosbench-openstack.pdf
 
JCache Using JCache
JCache Using JCacheJCache Using JCache
JCache Using JCache
 
Resume_CQ_Edward
Resume_CQ_EdwardResume_CQ_Edward
Resume_CQ_Edward
 
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance TuningPyCon US 2012 - Web Server Bottlenecks and Performance Tuning
PyCon US 2012 - Web Server Bottlenecks and Performance Tuning
 
PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + Memcached
 
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
 
Improving PHP Application Performance with APC
Improving PHP Application Performance with APCImproving PHP Application Performance with APC
Improving PHP Application Performance with APC
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
[Hic2011] using hadoop lucene-solr-for-large-scale-search by systex
[Hic2011] using hadoop lucene-solr-for-large-scale-search by systex[Hic2011] using hadoop lucene-solr-for-large-scale-search by systex
[Hic2011] using hadoop lucene-solr-for-large-scale-search by systex
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 

Último

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Último (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

PostgreSQL Query Cache - "pqc"

  • 1. PostgreSQL Query Cache “pqc” March/1/2011 Satoshi Nagayasu Uptime Technologies, LLC. Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 2. Overview • By caching result responses from backend, a query cache daemon (`pqcd’) makes query response faster “extremely” (x10~x100). – Delegates queries in front of the backend, like a proxy. – Waits connections on the different port (9999 by default). – Intercepts and caches SELECT query results. (Query Cache) – Manages lifecycle of the query cache. Server side Direct execution PostgreSQL PostgreSQL client backend(s) Execution pqcd with the query cache Cache Memory Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 3. Tech Specs • Supports simple query executions, and prepared statements. – Supports V3 protocol only. (V2 is not supported) • Supports “Active cache mode” – All SELECT query results would be stored in the query cache. – User specified query would not be cached. • Supports “Passive cache mode” – All SELECT query results would NOT be cached. – Only user specified SELECT queries would be cached. – And/or queries which took longer execution time than the user-specified duration, would be cached. (Not implemented yet) • Supports cache invalidation (expiration or refreshing) – By using the cache expiration timeout. – By using “hint” with SELECT statements. – By using “hint” to expire all query cache. (Not implemented yet) Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 4. The Query Cache Flow Overview • After `pqcd’ receives a SELECT statement, if some result is available in the query cache, `pqcd’ returns the result from the query cache. If not available, it relays the query to the backend. Receive a query from frontend Is cache No available? Yes Not expired No Invalidate Forward the query yet? the cache to backend Yes Fetch a result Retreive a result from query cache from the backend Store a result Send to the frontend in the query cache Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 5. Implementation • Using KVS (Memcached) to hold the query cache. – “libmemcached” as a memcached client library for C. – A SQL statement as a key, and response messages as a value. • `pqcd’, a query cache daemon, is implemented as a derivative of pgpool. – Un-used feature (code) removed, and several “hook” routines added. Server side PostgreSQL PostgreSQL client pqcd backend(s) Hook routines libmemcached Memcached Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 6. Deployment • Required packages – libevent 1.4.14b (required by memcached) – memcached 1.4.5 – libmemcached 0.43 • How to install – automake – ./configure --prefix=$PREFIX – make – sudo make install – cd $PREFIX/etc – cp pqcd_hba.conf.sample pqcd_hba.conf • Starting pqcd – $PREFIX/bin/pqcd • Stopping pqcd – $PREFIX/bin/pqcd stop Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 7. Deployment (with RPMs) • Required RPM – uqc-libevent-1.4.14b-1.i386.rpm – uqc-memcached-1.4.5-1.i386.rpm – uqc-libmemcached-0.43-1.i386.rpm – uqc-querycache-20110223-1.i386.rpm • Configuration files – /opt/uptime/querycache/etc/pqcd.conf – /opt/uptime/querycache/etc/pqcd_hba.conf • Starting pqcd – /opt/uptime/querycache/bin/pqcd • Stopping pqcd – /opt/uptime/querycache/bin/pqcd stop Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 8. Configurations • `pqcd.conf’ may be configured as you need. (in $PREFIX/etc) • memcached_bin – A path name to Memcached executable. (default is “/opt/uptime/querycache/bin/memcached”) • query_cache_mode – The query cache mode. “active” or “passive”. (default is “active”) • query_cache_expiration – The timeout value for query cache expiration (in seconds, default is 30) Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 9. Cache hints • Add as a comment at the beginning of SELECT statements – /* cache:refresh */SELECT * FROM … – <slash> <asterrisk> <space> <hint> <space> <asterisk> <slash> • cache:on (default in Active cache mode) – Looks at the cache first. If not found, then executes on the backend, and puts the result into the cache. • cache:off (default in Passive cache mode) – Doesn’t look at the cache. Execute on the backend first, and doesn’t put the result into the cache. • cache:refresh – Doesn’t look at the cache first. Executes on the backend, and puts the result into the cache. • cache:expire – Invalidates query cache for specified statement. (Not implemented yet) • cache:expireall – Invalidates all query cache. (Not implemented yet) Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 10. Examples Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 11. Query execution and the cache A regular scan takes >400ms. 2nd execution completes in 0.5ms with the cache. Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 12. A hint to handle the cache. Add a hint to disable the query cache. Longer time. Without a hint, the query cache again. Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 13. Record updates and the cache Delete all records. Still an old value left in the cache. Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 14. Refreshing the query cache Add a hint to refresh the cache. The value in the cache refreshed. With hitting the cache. Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 15. TODO • To Do – Handle a transaction state correctly on “Z (ready for query)” response. – Make expandable cache values for >8192bytes. – Make enable to handle cache key with >250 charactors. (limitation from Memcached) – Automatic query caching by watching duration time under the Passive cache mode. – Run benchmarks! • Done – PreparedStatement. – Cache hints. – Rename the binary to ‘pqcd’ in Makefile – Start/stop Memcached from pqcd. – Invalidation query cache by timeout. (query_cache_expiration option) – Completes a pgbench run. – Remove V2 protocol code. (prevent to be conneced with V2 at startup) – `memcached_bin’ option added in pqcd.conf. – Put a connected database name into the cache key. – Remove un-used code (replication, master-slave, dual server under connection pooling) – “Keep it simple, stupid!” – Make it public as an opensource software! Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.
  • 16. Contact: Uptime Technologies, LLC. E-Mail: contact@uptime.jp Web: http://www.uptime.jp/ Copyright 2010-2011 Uptime Technologies, LLC. All rights reserved.