pejrich
I’ve noticed recently that the idle time for my queries is creeping up over 1k ms.
[debug] QUERY OK source="chats" db=0.8ms idle=1272.7ms
[debug] QUERY OK source="messages" db=0.8ms queue=0.7ms idle=1616.1ms
[debug] QUERY OK source="users" db=0.8ms idle=1185.4ms
I restarted my postgres, which brought it down, but within 3 get queries it was back up to over 1k ms.
[debug] QUERY OK source="users" db=0.6ms queue=0.1ms idle=204.0ms
[debug] QUERY OK source="chats" db=0.4ms idle=686.6ms
[debug] QUERY OK source="users" db=0.4ms idle=1605.8ms
It is slow for all schemas, so that makes me think it’s either an issue with my postgres, or maybe my app settings. What could be the cause of this?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
According to db_connection/lib/db_connection/log_entry.ex at 436101ab9678f7173d8284086536ee27ad8c05c5 · elixir-ecto/db_connection · GitHub
so the cause is probably rare requests.
pejrich
I’m a bit unclear about the metric, because whether I wait a while between requests (let’s say 10 seconds, while running them from the console), or fire a bunch off pretty quickly, the
idletime still seems to hover between 800-2k ms. Maybe it’s not an issue, but I was just curious what could cause it to be so high (if it even is high, but 1-2s in DB time seems like a long time).benwilson512
I’m not entirely sure why the numbers don’t go higher, but it isn’t measuring time in the database. You should be able to confirm that because the requests themselves don’t take 2 seconds to return.
fishcakez
tl;dr the
idletime is how long a connection was ready and enqueued in the connection pool waiting to be checked out by a process. Therefore we can be happy to see it above0.idletime is recorded to show how busy or not busy the connection pool is. During connection pool IO overload the idle time will be as close to0as it can be, not counting message passing overhead, because then the connections are always in use by processes running transactions/queries. If a connection is not immediately available there isqueuetime that is the time between when the request for a connection was sent and when a connection becomes available. This time has latency impact for processes running transaction/queries as they need to wait for a connection before they can perform a query because the connection pool does not have enough capacity.dbtime is the time spent holding onto to the connection, i.e. time spent actually using the database. Therefore the latency for the calling process isqueuetime plusdbtime.When the connection pool has extra capacity the
queuetime should always be as close0as it can be because a connection is available when requested. Only once the transaction rate is beyond what the connection pool can handle does thequeuetime increase. However that is a little late because latency is already impacted once it goes above ~0.idleallows us to see how close to havingqueuetime, the higher theidletime the more capacity we have in the connection pool.Perhaps a clearer way to think about it is if you see an
idletimeout of 100ms, that means we could have run 100ms worth ofdbtime on that connection since the last time that connection was used. So to be as efficient as possible on resource we would wantqueueandidleto both be near0. However because of the latency impact ofqueue, we should be happy to sacrifice someidletime to keepqueueat0when possible.Of course we can make
queuetime move to0by increasing the pool size. However if the pool is too largedbtime will suffer as the database becomes the bottleneck instead of the connection pool.If the application is not sending any queries for a prologued interval and then sends a query why is the
idletime capped? This occurs because idle connections periodically send a ping message to the database to try to ensure connectivity so that the connections are ready and live when needed, and we don’t need to attempt to connect when a query comes in. If we needed to reconnect then the database handshake time would add latency to the transaction/query being processed. The ping message resets the idle timer because an individual connection is unavailable from the pool during a ping. If it was left in the pool the connection would be blocked waiting for a pong response and incur a wait on the connection like just like a handshake. Pings are randomized to prevent all connection becoming busy at the same time.