SlideShare une entreprise Scribd logo
1  sur  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.

Contenu connexe

Tendances

Optimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloadsOptimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloadsdatamantra
 
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...Altinity Ltd
 
Presto At Treasure Data
Presto At Treasure DataPresto At Treasure Data
Presto At Treasure DataTaro L. Saito
 
Where is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkWhere is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkFlink Forward
 
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsEnd-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsHostedbyConfluent
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkFlink Forward
 
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...Databricks
 
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of FacebookTech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of FacebookThe Hive
 
Real-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache PinotReal-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache PinotXiang Fu
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Databricks
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesDatabricks
 
Demystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, UberDemystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, UberFlink Forward
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우PgDay.Seoul
 
Using ClickHouse for Experimentation
Using ClickHouse for ExperimentationUsing ClickHouse for Experimentation
Using ClickHouse for ExperimentationGleb Kanterov
 
Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseAltinity Ltd
 
Redis cluster
Redis clusterRedis cluster
Redis clusteriammutex
 

Tendances (20)

Optimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloadsOptimizing S3 Write-heavy Spark workloads
Optimizing S3 Write-heavy Spark workloads
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
ClickHouse Data Warehouse 101: The First Billion Rows, by Alexander Zaitsev a...
 
Presto At Treasure Data
Presto At Treasure DataPresto At Treasure Data
Presto At Treasure Data
 
Where is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkWhere is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in Flink
 
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsEnd-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in Flink
 
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
Hudi: Large-Scale, Near Real-Time Pipelines at Uber with Nishith Agarwal and ...
 
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of FacebookTech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
 
Real-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache PinotReal-time Analytics with Trino and Apache Pinot
Real-time Analytics with Trino and Apache Pinot
 
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
 
Prestogres internals
Prestogres internalsPrestogres internals
Prestogres internals
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Demystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, UberDemystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, Uber
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
The basics of fluentd
The basics of fluentdThe basics of fluentd
The basics of fluentd
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우
 
Using ClickHouse for Experimentation
Using ClickHouse for ExperimentationUsing ClickHouse for Experimentation
Using ClickHouse for Experimentation
 
Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouse
 
Redis cluster
Redis clusterRedis cluster
Redis cluster
 

Similaire à 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
 

Similaire à 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
 

Dernier

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Dernier (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

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.