Git Product home page Git Product logo

Comments (8)

leafo avatar leafo commented on September 7, 2024

In what environment are you using pgmoon? It doesn't include a connection pool implementation. If you're using openresty then you can use the size parameter with the keepalive method: https://github.com/openresty/lua-nginx-module#tcpsocksetkeepalive

from pgmoon.

chirkin avatar chirkin commented on September 7, 2024

Yes, I'm using openresty environment. I tried size parameter on nginx socket, but it's not working, over size connections is not discarded. Need to create some tests for you?

from pgmoon.

ttfkam avatar ttfkam commented on September 7, 2024

I was under the impression that size prevented the number of connections from dropping below a certain number in the pool—the pool size—not limit the total connections to the server. To limit the total connections to the server, I would think you would put a limit in your PostgreSQL's postgresql.conf.

max_connections = 20

Not very fine-grained, I admit. Alternatively you could install a connection pooler like pgbouncer and using max_db_connections. This would allow your code to connect at will but prevent overloading the database with open sockets.

from pgmoon.

yzk0281 avatar yzk0281 commented on September 7, 2024

I change the pgmoon/init.lua file, function keepalive:
keepalive = function(self, ...)
local sock = self.sock
self.sock = nil
return sock:setkeepalive(50, 5)
--return sock:setkeepalive(...)
end,
so far we test good to imit the number of connections.

from pgmoon.

devvit avatar devvit commented on September 7, 2024

In truth, just put "lua_socket_pool_size" to your nginx.conf

from pgmoon.

gzliudan avatar gzliudan commented on September 7, 2024

in my postgresql.conf:
max_connections = 1024

in my nginx.conf
worker_processes 2;

in my test.lua file:
pg:keepalive(300000, 500)

when I use ab to test:
ab -n 100000 -c 1500 -s 300 -k 127.0.0.1/test

postgresql reports many below messages in log file:
sorry, too many clients already
remaining connection slots are reserved for non-replication superuser connections

from pgmoon.

gzliudan avatar gzliudan commented on September 7, 2024

add:
lua_socket_pool_size 500;
to nginx.conf cann't resolve this problem

from pgmoon.

leafo avatar leafo commented on September 7, 2024

lua_socket_pool_size does not resolve the problem as @ttfkam pointed out. The pool size is the numer of connections kept open. It will not block new connections from being created. pgbouncer is probably the most reliable solution, otherwise you can keep track of connection count yourself in a shared dict and reject new connections (or sleep) if connection count is larger than what you expect.

I don't think limiting number of connections is in the domain of this library, so I'm going to close the ticket.

from pgmoon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.