GPRC is very slow compared to HTTP service bindings when using workers smart placement
I have created 2 workers and have a service binding of one worker in another. When i call Worker B from Worker A and smart placement is enabled for Worker B, using RPC vs HTTP , RPC is very slow compared to HTTP. This is exactly as mentioned at https://developers.cloudflare.com/workers/configuration/smart-placement/#best-practices
Am i missing something ?
Worker A Code:
----------------
export default {
async fetch(request, env) {
const http_start_time = Date.now();
await env.BACKEND_ORIGIN.fetch(request);
const http_runtime = Date.now() - http_start_time;
const rpc_start_time = Date.now();
await env.BACKEND_ORIGIN.getComments();
const rpc_runtime = Date.now() - rpc_start_time;
return Response.json({http_runtime, rpc_runtime})
},
};
Worker B Code:
----------------
import { WorkerEntrypoint } from 'cloudflare:workers';
export default class BackendOrigin extends WorkerEntrypoint<Env> {
async fetch(): Promise<Response> {
const { results } = await this.env.D1_DEMO_DB.prepare('SELECT * FROM comments').all();
return Response.json(results);
}
async getComments() {
const { results } = await this.env.D1_DEMO_DB.prepare('SELECT * FROM comments').all();
return Response.json(results);
}
}
Response From Worker A:
---------------------------
{"http_runtime":289,"rpc_runtime":1217}
Consistently i am seeing that HTTP is almost 4x faster than RPC
Cloudflare Docs
Smart Placement · Cloudflare Workers docs
Speed up your Worker application by automatically placing your workloads in an optimal location that minimizes latency.
2 Replies
Oops sorry my bad, Updated the post
Ultra slow for me too with the same setup (service binding / entrypoint / d1).
Just tested this and indeed it is 4x slower via Service Binding Entrypoint than via fetch.
Where can we report this if not intentional?
@Walshy | Workers/Pages I am sorry if I tagged you wrongly :NotLikeThis: , but not sure who to tag or where to reach out. Thanks!