mohanram
CDCloudflare Developers
•Created by mohanram on 12/6/2024 in #workers-help
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
5 replies