Can I create a "non-edge" worker?

Hi there, I've been experimenting with workers, but I'm realizing that, because they run "at the edge", their performance is really bad if they need to talk with a database. If you need to talk with a database, you want your application code to live next to the database to reduce latency, but because Workers live "on the edge" they introduce a ton of back-and-forth latency to the database (like, 20x+ slower than if they lived near the database). Is it possible to create a worker that always lives in a specific location (i.e. next to the database) and isn't "on the edge"? For an application communicating with a database in a fixed location, being "on the edge" appears to only be a bad thing (i.e. in the best case, an edge worker will be as fast as a worker co-located next to the database but, in most cases, will be much slower).
5 Replies
Chaika
Chaika7mo ago
Sounds like you're looking for Smart Placement: https://blog.cloudflare.com/announcing-workers-smart-placement/ Only works with Fetch handlers/http requests though
The Cloudflare Blog
Smart Placement speeds up applications by moving code close to your...
Smart Placement automatically places your workloads in an optimal location that minimizes latency and speeds up your applications!
Chaika
Chaika7mo ago
Smart Placement (beta) · Cloudflare Workers docs
Speed up your Worker application by automatically placing your workloads in an optimal location that minimizes latency.
Chaika
Chaika7mo ago
(This won't work with TCP Connect(), if you're using that, hyperdrive (https://blog.cloudflare.com/hyperdrive-making-regional-databases-feel-distributed/) can help a fair bit though)
Zeri
Zeri7mo ago
This won't work with TCP Connect()
I am connecting to Postgres via pg and responses cannot be stale. This isn't the answer I was hoping for but thanks for the information!
Chaika
Chaika7mo ago
Hyperdrive isn't just about caching. Connection pooling is its other main benefit, only opening a few connections per region: https://developers.cloudflare.com/hyperdrive/learning/how-hyperdrive-works/, and keeping tcp connections around, which can help a lot. You can disable caching entirely: https://developers.cloudflare.com/hyperdrive/learning/query-caching/ Smart Placement plans to support TCP Connections one day, just not right now. Not sure how that'll play with hyperdrive though
Query caching · Hyperdrive
Hyperdrive automatically caches the most popular queries executed against your database, reducing the need to go back to your database (incurring …