Comments (10)
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.
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.
Huge thanks, @haikyuu, this is a great start. A few thoughts:
-
onRelease
,onAcquire
, andonConnect
should accept promise-returning functions, so that it's possible to use async functions for them.So
interface ReleaseCallback{ void: any }
becomestype 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 asacquire() => Promise<ConnectionProxy>
. All other connection-returning or -accepting APIs should work with proxies. -
expireConnections
andsetConnectionArguments
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 theconnect()
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.
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.
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
from edgedb-js.
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.
server-side connection pooling
What do you mean? Is it the maximum number of connections i specify when configuring a Port
?
from edgedb-js.
@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.
Sure, let's do that.
This is a direct port the python driver pool:
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.
@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.
from edgedb-js.
Related Issues (20)
- Bug in backslash escaping of TS query generation
- Add `.gitignore` in `@edgedb/create`
- If modules have types that have the same name, the interfaces generator creates invalid references to the default module.
- Wrong property types when access a link
- "No function overload function" when user-defined scalar used as function parameter HOT 1
- "function $x does not exist" when using optional function parameters
- In create app template, if auth is not fully configured, show a helpful message
- Type-aware query middleware HOT 2
- Create a consistent `@edgedb/create` app UI
- Auth/nextjs: The `onEmailVerify` fails with `no pkce verifier` when resending the verification email. HOT 1
- Docs: bulk insert needs `e.json_get`
- Support new branch connection argument
- Object cast cardinality not inferred from expression
- Add `npx edgedb` binary command that forwards commands to EdgeDB CLI and installs the CLI if it's missing
- Invalid path from object casts
- Error: Type instantiation is excessively deep and possibly infinite. HOT 4
- query builder: variables are generated in the wrong scope HOT 1
- Support link properties on backlinks HOT 1
- Can't access link properties on computed backlinks
- Queries generator inference error query instead queryRequiredSingle HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from edgedb-js.