Skip to content

Commit 847ad47

Browse files
committed
thomasgauvin: update how hyperdrive works for mysql
1 parent dc75ae6 commit 847ad47

File tree

3 files changed

+170
-31
lines changed

3 files changed

+170
-31
lines changed

src/assets/images/hyperdrive/configuration/hyperdrive-comparison.svg

Lines changed: 138 additions & 1 deletion
Loading

src/content/docs/hyperdrive/configuration/how-hyperdrive-works.mdx

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,52 @@ Traditional databases usually handle a maximum number of connections. With any r
1313

1414
Hyperdrive solves these challenges by managing the number of global connections to your origin database, selectively parsing and choosing which query response to cache while reducing loading on your database and accelerating your database queries.
1515

16+
## How Hyperdrive makes databases fast globally
17+
18+
Hyperdrive is accelerates database queries by performing the connection setup for new database connections near your Workers, pools existing connections near your database, and caches query results.
19+
This ensures you have optimal performance when connecting to your database from Workers (whether your queries are cached or not).
20+
1621
![Hyperdrive connection](~/assets/images/hyperdrive/configuration/hyperdrive-comparison.svg)
1722

18-
## Edge connection setup
23+
### 1. Edge connection setup
1924

20-
When a database driver connects to a database from a Cloudflare Worker (illustrated above on the right half of the diagram in **Direct (without Hyperdrive)**) it will first go through the connection setup. This may require multiple round trips to the database in order to verify and establish a secure connection. This can incur additional network latency due to the distance between your Cloudflare Worker and your database.
25+
When a database driver connects to a database from a Cloudflare Worker **directly**, it will first go through the connection setup. This may require multiple round trips to the database in order to verify and establish a secure connection. This can incur additional network latency due to the distance between your Cloudflare Worker and your database.
2126

22-
**With Hyperdrive** (on the left half of the above diagram), this connection setup occurs between your Cloudflare Worker and Hyperdrive on the edge, as close to your Worker as possible. This incurs significantly less latency, since the connection setup is completed within the same location.
27+
**With Hyperdrive**, this connection setup occurs between your Cloudflare Worker and Hyperdrive on the edge, as close to your Worker as possible (see diagram, label _1. Connection setup_). This incurs significantly less latency, since the connection setup is completed within the same location.
2328

24-
## Connection Pooling
29+
### 2. Connection Pooling
2530

2631
Hyperdrive creates a pool of connections to your database that can be reused as your application executes queries against your database.
2732

2833
The pool of database connections is placed in one or more regions closest to your origin database. This minimizes the latency incurred by roundtrips between your Cloudflare Workers and database to establish new connections. This also ensures that as little network latency is incurred for uncached queries.
2934

30-
When a query hits Hyperdrive, the request is routed to the nearest connection pool.
31-
32-
If the connection pool has pre-existing connections, the connection pool will try and reuse that connection.
33-
35+
If the connection pool has pre-existing connections, the connection pool will try and reuse that connection (see diagram, label _2. Existing warm connection_).
3436
If the connection pool does not have pre-existing connections, it will establish a new connection to your database and use that to route your query. This aims at reusing and creating the least number of connections possible as required to operate your application.
3537

3638
:::note
3739

3840
Hyperdrive automatically manages the connection pool properties for you, including limiting the total number of connections to your origin database. Refer to [Limits](/hyperdrive/platform/limits/) to learn more.
3941
:::
4042

41-
## Pooling mode
42-
43-
The Hyperdrive connection pooler operates in transaction mode, where the client that executes the query communicates through a single connection for the duration of a transaction. When that transaction has completed, the connection is returned to the pool.
44-
45-
Hyperdrive supports [`SET` statements](https://www.postgresql.org/docs/current/sql-set.html) for the duration of a transaction or a query. For instance, if you manually create a transaction with `BEGIN`/`COMMIT`, `SET` statements within the transaction will take effect. Moreover, a query that includes a `SET` command (`SET X; SELECT foo FROM bar;`) will also apply the `SET` command. When a connection is returned to the pool, the connection is `RESET` such that the `SET` commands will not take effect on subsequent queries.
46-
47-
This implies that a single Worker invocation may obtain multiple connections to perform its database operations and may need to `SET` any configurations for every query or transaction. It is not recommended to wrap multiple database operations with a single transaction to maintain the `SET` state. Doing so will affect the performance and scaling of Hyperdrive as the connection cannot be reused by other Worker isolates for the duration of the transaction.
48-
49-
Hyperdrive supports named prepared statements as implemented in the `postgres.js` and `node-postgres` drivers. Named prepared statements in other drivers may have worse performance.
43+
### 3. Query Caching
5044

51-
## Unsupported PostgreSQL features:
45+
Hyperdrive supports caching of non-mutating (read) queries to your database.
5246

53-
Hyperdrive does not support the following PostgreSQL features:
47+
When queries are sent via Hyperdrive, Hyperdrive parses the query and determines whether the query is a mutating (write) or non-mutating (read) query.
5448

55-
- SQL-level management of prepared statements, such as using `PREPARE`, `DISCARD`, `DEALLOCATE`, or `EXECUTE`.
56-
- Advisory locks ([PostgreSQL documentation](https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS)).
57-
- `LISTEN` and `NOTIFY`.
58-
- `PREPARE` and `DEALLOCATE`.
59-
- Any modification to per-session state not explicitly documented as supported elsewhere.
49+
For non-mutating queries, Hyperdrive will cache the response for the configured `max_age`, and whenever subsequent queries are made that match the original, Hyperdrive will return the cached response, bypassing the need to issue the query back to the origin database.
6050

61-
In cases where you need to issue these unsupported statements from your application, the Hyperdrive team recommends setting up a second, direct client without Hyperdrive.
51+
Caching reduces the burden on your origin database and accelerates the response times for your queries.
6252

63-
## Query Caching
53+
## Pooling mode
6454

65-
Hyperdrive supports caching of non-mutating (read) queries to your database.
55+
The Hyperdrive connection pooler operates in transaction mode, where the client that executes the query communicates through a single connection for the duration of a transaction. When that transaction has completed, the connection is returned to the pool.
6656

67-
When queries are sent via Hyperdrive, Hyperdrive parses the query and determines whether the query is a mutating (write) or non-mutating (read) query.
57+
Hyperdrive supports [`SET` statements](https://www.postgresql.org/docs/current/sql-set.html) for the duration of a transaction or a query. For instance, if you manually create a transaction with `BEGIN`/`COMMIT`, `SET` statements within the transaction will take effect. Moreover, a query that includes a `SET` command (`SET X; SELECT foo FROM bar;`) will also apply the `SET` command. When a connection is returned to the pool, the connection is `RESET` such that the `SET` commands will not take effect on subsequent queries.
6858

69-
For non-mutating queries, Hyperdrive will cache the response for the configured `max_age`, and whenever subsequent queries are made that match the original, Hyperdrive will return the cached response, bypassing the need to issue the query back to the origin database.
59+
This implies that a single Worker invocation may obtain multiple connections to perform its database operations and may need to `SET` any configurations for every query or transaction. It is not recommended to wrap multiple database operations with a single transaction to maintain the `SET` state. Doing so will affect the performance and scaling of Hyperdrive as the connection cannot be reused by other Worker isolates for the duration of the transaction.
7060

71-
Caching reduces the burden on your origin database and accelerates the response times for your queries.
61+
Hyperdrive supports named prepared statements as implemented in the `postgres.js` and `node-postgres` drivers. Named prepared statements in other drivers may have worse performance.
7262

7363
## Related resources
7464

src/content/docs/hyperdrive/reference/supported-databases.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ Hyperdrive supports the following [authentication modes](https://www.postgresql.
2828
- Password Authentication (`md5`)
2929
- Password Authentication (`password`) (clear-text password)
3030
- SASL Authentication (`SCRAM-SHA-256`)
31+
32+
## Unsupported PostgreSQL features:
33+
34+
Hyperdrive does not support the following PostgreSQL features:
35+
36+
- SQL-level management of prepared statements, such as using `PREPARE`, `DISCARD`, `DEALLOCATE`, or `EXECUTE`.
37+
- Advisory locks ([PostgreSQL documentation](https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS)).
38+
- `LISTEN` and `NOTIFY`.
39+
- `PREPARE` and `DEALLOCATE`.
40+
- Any modification to per-session state not explicitly documented as supported elsewhere.
41+
42+
In cases where you need to issue these unsupported statements from your application, the Hyperdrive team recommends setting up a second, direct client without Hyperdrive.

0 commit comments

Comments
 (0)