Code Monkey home page Code Monkey logo

Comments (10)

1st1 avatar 1st1 commented on May 20, 2024 1

The concurrency setting of a Port corresponds to two things: the number of Python compiler processes and the number of Postgres connections in the pool of this port. Setting concurrency := 5 means that there will be 5 postgres connections in the pool managed for you automatically.

from edgedb-js.

1st1 avatar 1st1 commented on May 20, 2024 1

I know you've implemented one for the python driver so you have more context about that.

I'd start with examining the Python implementation and prototyping a JS one based on it. Maybe we can start drafting the API / types / methods / functions first (using the TS syntax).

from edgedb-js.

1st1 avatar 1st1 commented on May 20, 2024 1

Huge thanks, @haikyuu, this is a great start. A few thoughts:

  • onRelease, onAcquire, and onConnect should accept promise-returning functions, so that it's possible to use async functions for them.

    So interface ReleaseCallback{ void: any } becomes type ReleaseCallback = (connection: Connection) => Promise<void>.

  • We need to implement proxy objects for Connections. The idea is that our Pool would not give you a real Connection object, but instead return a wrapper. A wrapper is only valid to use until it's released.

    This makes it difficult for people to accidentally re-use already released connections.

    Essentially it means that Pool.acquire would be defined as acquire() => Promise<ConnectionProxy>. All other connection-returning or -accepting APIs should work with proxies.

  • expireConnections and setConnectionArguments are rather low priority, we don't need them in the very first iteration.

  • Regarding implementation: we want to keep edgedb-js to have 0 dependencies. Means that we'll probably need to implement a LIFO queue ourselves; good news is that 70% of it are already implemented in lru.ts.

  • Lastly, it would be great if createPool had two signatures (like the connect() function):

    function connect(options: PoolConfig): Promise<AwaitPool> and
    function connect(options: PoolConfig, NodeCallback<Pool>): void

    This makes it possible to use our pool API with both styles: nodejs callbacks and async/await. Please take a look at how client.ts is structured.

Other than that the diagram looks correct!

from edgedb-js.

haikyuu avatar haikyuu commented on May 20, 2024

Is there some progress on this?

In the meantime, what should i do to circumvent this limitation? Should i open a new connection for each request? Or is there another way?

I did some research and it seems like there is a generic pool https://www.npmjs.com/package/generic-pool.

I'll give it a try and share my findings

from edgedb-js.

haikyuu avatar haikyuu commented on May 20, 2024

I tried using the generic pool and it didn't work reliably.

Is there a way to access:

  • The number of open connections
  • Memory used by edgedb

Those will help me debug.

For now, when i run edgedb service, i notice these processes are run

image

from edgedb-js.

1st1 avatar 1st1 commented on May 20, 2024

In the meantime, what should i do to circumvent this limitation? Should i open a new connection for each request?

Yeah, without a proper pool that's the only solution. Or use edgeql+http or graphql+http port (that way you essentially have a server-side connection pooling).

The number of open connections

Not yet. We need to add that.

from edgedb-js.

haikyuu avatar haikyuu commented on May 20, 2024

@1st1

server-side connection pooling

What do you mean? Is it the maximum number of connections i specify when configuring a Port?

from edgedb-js.

haikyuu avatar haikyuu commented on May 20, 2024

@1st1 I'm interested in implementing a pool for the js driver. Can you help me in that? from where should i start? How is it done in EdgeDB side of things? ...

I know you've implemented one for the python driver so you have more context about that.
Thank you

from edgedb-js.

haikyuu avatar haikyuu commented on May 20, 2024

Sure, let's do that.

This is a direct port the python driver pool:

image

import {ConnectConfig} from "./con_utils";
import {Connection} from "./client";

interface PoolConfig{
    connectionConfig: ConnectConfig,
    minSize: number,
    maxSize: number,
    onRelease?: ReleaseCallback,
    onAcquire?: AcquireCallback,
    onConnect?: ConnectCallback,
}

interface createPool {
  PoolConfig: Promise<Pool>
}
interface ReleaseCallback{ void: any }
interface AcquireCallback{ void: any }
interface ConnectCallback{ Connection: any }

interface Pool{
  acquire (): Promise<Connection>
  release (Connection): Promise<void>
  terminate (): Promise<void>
  close (): Promise<void>
  expireConnections (): Promise<void>
  setConnectionArguments (ConnectConfig): Promise<void>
}

What's the use of the Proxy that is passed to the acquire callback in the python driver?

from edgedb-js.

haikyuu avatar haikyuu commented on May 20, 2024

@1st1 what do you think about these definitions? Should we move forward?

I think the first thing we should implement is the acquire method.

I sketched a little drawing that shows how acquire works under the hood. I'd like to get your feedback on it.
acquire

from edgedb-js.

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.