This PR introduces a series of optimizations both in shared component code and in the router.
Changes
While building a JWT token, do not convert the private key to []byte, then back to the *ecdsa.PrivateKey format. Instead, just pass the *ecdsa.PrivateKey directly.
Reuse the JWT token between all of the broker requests. This is still not ideal since we should share the token between separate activations as well, but it is what it is.
Wait only for the first successful activation downlink, instead of waiting for duplicates as well.
Combine the router gRPC handlers with the code in api/router/routerclient/server_streams in order to lower the number of active goroutines and channels. This saves us 3 goroutines per gateway.
Move the router downlink tracing (from router to gateway) inside the gRPC handler. This saves us one goroutine per gateway.
Create an upper bound of concurrent downlink handlers per broker. Currently set to 64 handlers per broker. There is only one uplink handler per broker since the api package already does multiplexing.
Testing
Unit tests.
Notes for Reviewers
We save 4 goroutines per gateway with this PR, which in large deployments amounts to about 20% less goroutines (wrt total amount per instance). This allows us to save a significant amount of memory and CPU costs.
This targets update/deps in order to separate the changes.
Checklist
[x] Scope: The referenced issue is addressed, there are no unrelated changes.
[x] Compatibility: The changes are backwards compatible with existing API, storage, configuration and CLI, according to the compatibility commitments in README.md for the chosen target branch.
[ ] Documentation: Relevant documentation is added or updated.
[ ] Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.
[x] Commits: Commit messages follow guidelines in CONTRIBUTING.md, there are no fixup commits left.
Summary
This PR introduces a series of optimizations both in shared component code and in the router.
Changes
[]byte
, then back to the*ecdsa.PrivateKey
format. Instead, just pass the*ecdsa.PrivateKey
directly.router
togateway
) inside the gRPC handler. This saves us one goroutine per gateway.64
handlers per broker. There is only one uplink handler per broker since theapi
package already does multiplexing.Testing
Unit tests.
Notes for Reviewers
We save 4 goroutines per gateway with this PR, which in large deployments amounts to about 20% less goroutines (wrt total amount per instance). This allows us to save a significant amount of memory and CPU costs.
This targets
update/deps
in order to separate the changes.Checklist
README.md
for the chosen target branch.CHANGELOG.md
.CONTRIBUTING.md
, there are no fixup commits left.