Skip to content

Server: Installation

Bill Thompson edited this page Aug 31, 2021 · 5 revisions

Installing gruf as a server is fairly straightforward. First, add the gem to your Gemfile:

gem 'gruf'

Then in an initializer or before use:

require 'gruf'

You can configure and customize Gruf further:

Gruf.configure do |c|
  c.server_binding_url = 'grpc.service.com:9003'
end

GRPC::RpcServer configuration

To customize parameters for the underlying GRPC::RpcServer, such as the size of the gRPC thread pool, you can pass them in via Gruf.rpc_server_options.

Gruf.configure do |c|
  # The size of the underlying thread pool. No more concurrent requests can be made
  # than the size of the thread pool.
  c.rpc_server_options = c.rpc_server_options.merge(pool_size: 100)
end

Gruf uses the DEFAULT_POOL_SIZE from grpc to determine the default thread pool size - 30. Therefore, each Gruf process can handle 30 concurrent requests.

You should tune this number to match your application performance characteristics to ensure your application is not being starved of CPU or RAM.

Additionally, you will need to ensure that your ActiveRecord database connection pool size matches or exceeds the gRPC pool size if each thread needs to be able to make database calls concurrently. Your database (MySQL or Prostgres) max user connections setting should be adjusted to ensure each database connection in the ActiveRecord connection pool can establish a valid connection.

Upgrading

Make sure to review UPGRADING.md if you are upgrading gruf between minor or major versions.


Next: Generating Stubs