Created
April 25, 2021 11:00
-
-
Save fantasywind/b37941406a51aec88c2205366208d37f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SIZE = 500000; | |
const path = require('path'); | |
const grpc = require('@grpc/grpc-js'); | |
const protoLoader = require('@grpc/proto-loader'); | |
const PROTO_PATH = path.resolve(__dirname, './grpc.proto'); | |
const GRPC_HOST = '127.0.0.1:50099'; | |
const packageDeginition = protoLoader.loadSync(PROTO_PATH); | |
const descriptor = grpc.loadPackageDefinition(packageDeginition); | |
const grpcClient = new descriptor.Test( | |
GRPC_HOST, grpc.credentials.createInsecure() | |
); | |
// Test GRPC | |
const grpcServer = new grpc.Server(); | |
grpcServer.addService(descriptor.Test.service, { | |
TextSend: (call, callback) => { | |
console.timeEnd('gRPC:Transmission'); | |
callback(null, { done: true }); | |
}, | |
}); | |
grpcServer.bindAsync(GRPC_HOST, grpc.ServerCredentials.createInsecure(), (err, s) => { | |
grpcServer.start(); | |
const generated = { | |
data: Array.from(Array(SIZE)).map((n, index) => ({ | |
index, | |
})), | |
}; | |
console.time('gRPC:Transmission'); | |
grpcClient.TextSend(generated, (err) => { | |
console.time('gRPC:Serialize'); | |
console.log(`gRPC:Size:${grpcClient.TextSend.requestSerialize(generated).length}`); | |
console.timeEnd('gRPC:Serialize'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment