Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC roundtrips on Windows are significantly slower in Electron renderer processes than in the Electron main process #489

Open
srubin opened this issue Aug 10, 2018 · 3 comments

Comments

@srubin
Copy link

srubin commented Aug 10, 2018

Problem description

I am using the grpc native node module in an Electron app. I expect similar roundtrip performance when sending gRPC messages in the main process vs. in the renderer process.

On macOS, performance is equivalent. On Windows, the roundtrip times for gRPC messages sent from the renderer process are, on average, ~200x slower than when sent from the main process.

Reproduction steps

This repo shows the described behavior: https://github.com/descriptinc/grpc-electron-test/tree/sr/electron-2.0

$ git clone -b sr/electron-2.0 https://github.com/descriptinc/grpc-electron-test
$ cd grpc-electron-test
$ yarn install

# in one terminal
$ node example/greeter_server.js

# in another terminal
$ yarn start

It runs the same gRPC test in the main process and in the renderer process and then shows the results in the renderer BrowserWindow. It computes the average round-trip time for a simple gRPC message (200 messages, sent at an interval of 10 ms. The problem persists even if the interval is much greater).

On Windows I get a result like:

Average gRPC roundtrip (running in main): 0.62ms
Average gRPC roundtrip (running in renderer): 145.94ms

While on macOS I get a result like:

Average roundtrip (running in main): 1.29ms
Average roundtrip (running in renderer): 1.33ms

Note: I get the expected behavior in Windows if I switch to the alpha/experimental @grpc/grpc-js module. See: https://github.com/descriptinc/grpc-electron-test/tree/sr/electron-3.0-grpc-js (Electron 3 is required because @grpc/grpc-js requires node >= 9.0.0).

Environment

  • OS name, version and architecture: Windows 10 64 bit, Windows Server 2016 (on EC2) 64 bit
  • Node version: 8.11.3
  • Node installation method: yarn
  • Package name and version: gRPC@1.13.1

Additional context

I'm not sure if the real issue here is in Electron or in gRPC. I opened an issue there, too: electron/electron#14011

I'm guessing that this is somehow related to the different way that Windows and Mac/Linux implement the node.js runtime binding in the renderer process, i.e.,

@nicolasnoble
Copy link
Member

As a sort of "if it hurts, don't do it", why not using the main process at all times to send RPCs? It's a bit less straightforward, but you could use electron's IPC from renderer to main in order to send and receive your messages. I've seen other electron apps doing this for the same reason, with other native modules than grpc.

@srubin
Copy link
Author

srubin commented Aug 10, 2018

Yeah, that’s certainly an option and probably the approach I’ll end up taking.

The main reason for “why not” is that we compute the gRPC messages based on model instances that we have access to in the renderer. So, there are a few ways to get that data (or the gRPC message data) to the main process, but they’re messier than sending those messages directly from the renderer.

I hope the existence of this bug report is useful for people using gRPC on Electron and Windows, even if there’s no plan on fixing it.

@nicolasnoble
Copy link
Member

Oh it's useful, don't worry. I'm curious about the rootcause itself. But I think it's generally an Electron thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants