Unusually high latency on Kubernetes cluster #2315
-
Environment
Description of issueHello 👋 I've been debugging this issue & I think this is related to just the PostgREST, and not with other configuration. I've deployed other service just fine on currently running cluster. Currently I'm trying to integrate the project with my current custom CRUD/REST backend system. I'm currently having an issue of the service having unusually (very) high latency. Sample: root@test-client:/# time curl -I postgrest.postgrest # Host for the postgrest service
HTTP/1.1 200 OK
Date: Mon, 13 Jun 2022 07:12:34 GMT
Server: postgrest/9.0.0
Content-Type: application/openapi+json; charset=utf-8
real 0m33.161s
user 0m0.006s
sys 0m0.009s And when I tried to just request it a couple more times, it would then be a more reasonable latency root@test-client:/# time curl -I postgrest.postgrest
HTTP/1.1 200 OK
Date: Mon, 13 Jun 2022 07:12:34 GMT
Server: postgrest/9.0.0
Content-Type: application/openapi+json; charset=utf-8
real 0m33.161s
user 0m0.006s
sys 0m0.009s
root@test-client:/# time curl -I postgrest.postgrest
HTTP/1.1 200 OK
Date: Mon, 13 Jun 2022 07:14:51 GMT
Server: postgrest/9.0.0
Content-Type: application/openapi+json; charset=utf-8
real 0m32.881s
user 0m0.007s
sys 0m0.007s
root@test-client:/# time curl -I postgrest.postgrest
HTTP/1.1 200 OK
Date: Mon, 13 Jun 2022 07:14:55 GMT
Server: postgrest/9.0.0
Content-Type: application/openapi+json; charset=utf-8
real 0m0.049s
user 0m0.007s
sys 0m0.007s
root@test-client:/# time curl -I postgrest.postgrest
HTTP/1.1 200 OK
Date: Mon, 13 Jun 2022 07:14:57 GMT
Server: postgrest/9.0.0
Content-Type: application/openapi+json; charset=utf-8
real 0m0.029s
user 0m0.007s
sys 0m0.005s Logs // ...
10.28.0.105 - - [13/Jun/2022:07:12:34 +0000] "HEAD / HTTP/1.1" 200 - "" "curl/7.83.1"
10.28.0.105 - - [13/Jun/2022:07:14:51 +0000] "HEAD / HTTP/1.1" 200 - "" "curl/7.83.1"
10.28.0.105 - - [13/Jun/2022:07:14:55 +0000] "HEAD / HTTP/1.1" 200 - "" "curl/7.83.1"
10.28.0.105 - - [13/Jun/2022:07:14:57 +0000] "HEAD / HTTP/1.1" 200 - "" "curl/7.83.1" Is there a way to get PostgREST to be more "verbose"? I'm currently trying to find the root cause on what causes such latency. Maybe this is related to the resource usage. Is there a minimum recommended spec for how much should PostgREST uses CPU/memory? Currently I limit the usage to The backing DB is already used by traffic, but I don't think that would causes the latency (on above I've only test using |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
I don't know about Kubernetes unfortunately. But on a lower end AWS t3a.nano instance(2 CPUs, 0.5 GB memory), I got a 32.52ms p95 latency while load testing from another instance in the same region. These were simple read requests(
Maybe try with simple read requests, OpenAPI could be slow if the db is complex. |
Beta Was this translation helpful? Give feedback.
-
No luck, the pattern is similar to current behaviour root@test-ruff-client:/# time curl -XGET postgrest.postgrest/users-public?id=eq.{user-id}
[{"id":"{user-id}","data": "..."]
real 0m34.076s
user 0m0.005s
sys 0m0.025s
root@test-ruff-client:/# time curl -XGET postgrest.postgrest/users-public?id=eq.{user-id}
[{"id":"{user-id}","data": "..."]
real 0m32.470s
user 0m0.005s
sys 0m0.011s
root@test-ruff-client:/# time curl -XGET postgrest.postgrest/users-public?id=eq.{user-id}
[{"id":"{user-id}","data": "..."]
real 0m0.019s
user 0m0.004s
sys 0m0.007s
root@test-ruff-client:/# time curl -XGET postgrest.postgrest/users-public?id=eq.{user-id}
[{"id":"{user-id}","data": "..."]
real 0m0.046s
user 0m0.006s
sys 0m0.006s The pattern is currently: 30s latency for few first request, and then it would be fine, but if I wait for a minute or two, then it would regress again. My suspect is that this is simply because of cache I guess the issue that I'm trying to trace is how did the latency get so high in the first place users_db=# EXPLAIN SELECT * FROM users WHERE id = '{user-id}'; -- The query should be fine, it basically takes no time
QUERY PLAN
---------------------------------------------------------------------------
Index Scan using users_pkey on users (cost=0.29..8.31 rows=1 width=1237)
Index Cond: (id = '{user-id}'::uuid)
(2 rows) I don't know if this might help, but what process/steps does PostgREST make whenever a request came in? maybe I can extrapolate/guess based on that to see if there's a specific part of the system resources to be adjusted. I still suspect that it might not play nice with how the CPU is scheduled on kubernetes |
Beta Was this translation helpful? Give feedback.
-
I am also using PostgREST on K8s and I don't have any problems. However, one big difference is I am using a Postgres Operator -> https://www.kubegres.io/ and therefore a Postgres Cluster is used. Some features like backup restore rolling updates, node migration resistency from Kubegres is something you will most likely have to solve in the future anyway. Hope this helps :) |
Beta Was this translation helpful? Give feedback.
No luck, the pattern is similar to current behaviour