Replies: 17 comments 110 replies
-
Hi, Sudeep
Do you mean you will do either idea 1 or 2? I think we might need to combine idea 1 and 2. Idea 1 query Idea 2 parse the SQL can be used in several ways:
|
Beta Was this translation helpful? Give feedback.
-
Hi @jesperpedersen |
Beta Was this translation helpful? Give feedback.
-
Hii @jesperpedersen , So here is how I plan to implement the caching system. I would be using uthash as the hashtable.
If the largest xmin values of a table are less than the one stored in the cache that means that the xmin values must have reset and thus we invalidate this cache. Also if the xmin value has increased we invalidate the cache. Only when the largest xmin value matches should we return the cached response. We would also be needing few functions, I'm planning on implementing the following:
We would need both |
Beta Was this translation helpful? Give feedback.
-
Hii @jesperpedersen I have updated the PR with tests. I have also modified the datatypes for key and data, also update the documentation for each function. Please have a look and let me know if I need to make any changes. |
Beta Was this translation helpful? Give feedback.
-
Hello @jesperpedersen, I would like your opinion on creating keys for cache entries. Here is the proposed approach So to my knowledge we can use two types of queries to query the PostgreSQL db,
My approach is to create a key struct that includes both the query and the bind parameters, like this:
if we get a Q message we store Could you please let me know if this approach is valid and provide your feedback on it? |
Beta Was this translation helpful? Give feedback.
-
Hi @jesperpedersen , so i have a couple of doubts after going through the session pipeline code, please correct me if my understanding is wrong anywhere
Now how do i define the caching layer? Ideally it should be in the |
Beta Was this translation helpful? Give feedback.
-
hi jesper, so i have implemented global lock, and also the size limits as we discussed over the email. And changed the cache structure to
So the caching mechanism works when i connect it directly to postgresql using psql (yeee progress 🥳 ) and there are no memory leaks in the logic i added.
|
Beta Was this translation helpful? Give feedback.
-
Continuing the discussion from email, to provide better visibility
Yes it works!
Yes i created a script with a basic query |
Beta Was this translation helpful? Give feedback.
-
Tests and ObservationsTest Suit 1
Test 1 (Without cache):
Test 2 (With Cache)
Test 3 (without pgagroal, using direct postgres)
Test Suit 2
Test 1 (Without cache):
Test 2 (With Cache):
Test 3 (without pgagroal, using direct postgres)
|
Beta Was this translation helpful? Give feedback.
-
Good that you have it working now. We can build from here |
Beta Was this translation helpful? Give feedback.
-
Hey Jesper,
pgbench output
|
Beta Was this translation helpful? Give feedback.
-
It sounds like you are reading passed the end of the key - make sure that the key is the query plus a |
Beta Was this translation helpful? Give feedback.
-
In But if it is connection level then it is local to the connection and you should only clear it upon client disconnect. The harder one is the global cache, where you have to use a lock... |
Beta Was this translation helpful? Give feedback.
-
Hi @jesperpedersen
The aim with this script is to add the query result to hash and then for the second query get the hashed result.
|
Beta Was this translation helpful? Give feedback.
-
Hi @jesperpedersen
So as you can see some entries from the cache are just malformed. idk why this is happening tho. |
Beta Was this translation helpful? Give feedback.
-
Hi @jesperpedersen
And i switched to All tests were done in release build, session pipeline Without cache:
With cache(uthash):
|
Beta Was this translation helpful? Give feedback.
-
Hi everyone👋🏻
I'm Sudeep Reddy, super glad to be selected as a GSoC'23 contributor for PostgreSQL.
I would be working on adding query caching functionality to pgagroal. This project will be focused more on RnD, trying different variations and testing the implementation. I hope by the end we are successfully able to have this functionality 🤞🏻 !
There are 2 main strategies I have in mind to implement this
xmin
values, to invalidate the cachecache timeouts
Here is my proposal, which goes deeper into the proposed ideas.
Please feel free to propose new ideas, ask questions and give feedback on my proposal!!
Final Outcome
After experimenting with various caching approaches, we have concluded that it would be more beneficial to operate pgagroal without a cache #376 (reply in thread).
Initially, the idea behind implementing a query cache was to reduce the database load in order to increase the number of transactions per second #58.
However, it became evident that caching had a negative impact on performance, as demonstrated by the graphs below.
All the tests were conducted in
release mode
and insession pipeline
.pgbench cmd used:
pgbench -S -M simple -c X -j X
All the work done is in this PR: #377.
Learnings
This project involved a substantial amount of debugging, particularly in addressing deadlocks and race conditions. I managed to get the basic caching API working by the time of the midterms. However, integrating it with the session pipeline proved to be quite challenging, leading to several issues:
1.1 [GSoC'23] Query Cache #376 (comment)
1.2 [GSoC'23] Query Cache #376 (comment)
2.1 https://groups.google.com/g/uthash/c/giaBpGoIoLU/m/xL7Vmf91oEsJ
3.1 [GSoC'23] Query Cache #376 (reply in thread).
4.1 [GSoC'23] Query Cache #376 (comment) .
5.1 [GSoC'23] Query Cache #376 (comment).
Conclusion and Future Work
Given the cache's poor performance, even with a small 'key' sample size, I am uncertain about how to enhance its functionality.
One important consideration to note is that these tests were conducted on a single machine, where both the database and pgagroal were running on the same system. The cache may potentially offer benefits in scenarios where communication with the database occurs over a network, but I have serious doubts regarding its effectiveness in such cases.
Beta Was this translation helpful? Give feedback.
All reactions