How to use pooling correctly? #1989
Unanswered
micahshell
asked this question in
Q&A
Replies: 2 comments 3 replies
-
You should create a pool to be used by your entire program. You are creating a new pool for each request. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Dang I missed that looking at your chat example , thanks! Basically have a global variable of a type *pgxpool.Pool? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm new to Go and want to write web apps using psql as my db, so I'm going to have to use connection pooling. Below is a simplified version of what I'm doing, my issue is that I don't think it's using more than one connection. I'm testing it using the ab command, from a separate machine.
Sending 100 reqs with 20 concurrent connections*
ab -c 20 -n 100 http://192.168.1.166:3000/data | grep "per second"
Here's the code:
Sorry it's a bit much, the login info for psql is just for testing...
The output of the stats looks like this for each request. Am I doing something wrong or is this expected?
Thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions