-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(db) improve kong startup time by reusing luasocket on kong.init #4178
Conversation
7831717
to
b963b1c
Compare
Without this patch the Postgres strategy creates 7 non-pooled luasocket connections to database on Kong.init(). This patch reduces that to 3. Without this patch the Cassandra strategy creates 9 non-pooled luasocket connections to database on Kong.init(). This patch reduces that to 1. The difference is because Postgres needs to run initialization SQL to setup the connection timezone and database schema on new connections. And for Postgres `connect_migrations` is the same as `connect` while with Cassandra it is not. It is still a tiny improvement for Postgres as well.
b963b1c
to
5b6bbd7
Compare
if not plugins_map_semaphore then | ||
error("failed to create plugins map semaphore: " .. err) | ||
end | ||
|
||
plugins_map_semaphore:post(1) -- one resource, treat this as a mutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, why this change? Seems unrelated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@p0pr0ck5 nothing, just a small cleanup as I was touching code close to it. Not a big deal to include or remove the change.
Hey folks I gave this PR a go on 1.0 GA and saw this error during startup in debug mode:
And init.lua line 360 was the assert db close in the newly modified snippet:
Just thought I would bring it to attention since I noticed this was indeed already merged if it raises any concerns. EDIT - commenting out the assert(db:close()) seems to have "dirty" fixed it, maybe thats not the right approach for the official pr. |
Summary
This is the seond PR that comes from the discussion of #4171.
Without this patch the Postgres strategy creates 7 non-pooled luasocket connections to database on Kong.init(). This patch reduces that to 3.
Without this patch the Cassandra strategy creates 9 non-pooled luasocket connections to database on Kong.init(). This patch reduces that to 1.
The difference is because Postgres needs to run initialization SQL to setup the connection timezone and database schema on new connections. And for Postgres
connect_migrations
is the sameas
connect
while with Cassandra it is not. It is still a tiny improvement for Postgres as well.