Code Monkey home page Code Monkey logo

Comments (3)

porsager avatar porsager commented on August 19, 2024

Types are only fetched at first connect. Are you running on some edge host? You can disable with fetch_types: false

from postgres.

phosmium avatar phosmium commented on August 19, 2024

@porsager Hey, this is not running on an edge host. The problem is, disabling fetch_types throws some exceptions as it can't resolve a type from an array it seems. It seems to be re-fetching the types on each connection in the pool, so when I have a lot of transactions and it grabs different connections, it will indeed re-fetch the types.

When there are high amount of concurrent queries, postgres will open as many connections as needed up until max number of connections is reached. By default max is 10. This can be changed by setting max in the postgres() call. Example - postgres('connectionURL', { max: 20 }).

This means that we get a much simpler story for error handling and reconnections. Queries will be sent over the wire immediately on the next available connection in the pool. Connections are automatically taken out of the pool if you start a transaction using sql.begin(), and automatically returned to the pool once your transaction is done.

^ The README explains that behavior, except the part that it re-fetches all types. Is there any possible way to cache the types? We have a ton of concurrent queries as it's an gameserver, it not caching and re-fetching the types is quite time consuming as we have a big database. We noticed high delays on a big player count (stuff that requires knowing array types, as that plays a role) and when we had a lot of concurrent queries going on at startup which was eating some seconds of boot time.

from postgres.

phosmium avatar phosmium commented on August 19, 2024

https://github.com/porsager/postgres/blob/master/src/connection.js#L743

This seems to be it, as needsTypes is scoped per connection and thus resulting in the re-fetch instead of re-using the already known types from a previous connection.

from postgres.

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.