Repository navigation
A service can be served in process, and its clients there call it directly - #40
Merged
Merged
Conversation
…ectly `local: true` on a service registers it, once started, with every client in its own process. Those clients call it through the same checks, hooks and method as a queued request, with no trip through the queue: the request and the answer are each copied through JSON, as the queue copies them, so dates, class instances and `undefined` arrive exactly as they would have, and neither side holds an object of the other's. The queue is still served, so a client in another process, a delayed call (which the queue holds until it is due) and `publish()` are unaffected, and the same service runs standalone wherever `local` is off. A client's `local: false` keeps it on the queue. The registry is anchored on the process, not the module, so a host that loads a service from its own directory, with that service's own copy of this package, still reaches it. A service served in process belongs to its host: it installs no signal handlers, does not drain, starts no metrics server and cannot fork workers. An answer that cannot be written as JSON rejects at once with IMQ_RPC_CALL_ERROR, where through the queue the call timed out.
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A service started with
local: trueregisters itself, once started, with every client in its own process, and those clients call it directly: the same checks, hooks (beforeCall,wrapCall,afterCallon both sides) and method as a queued request, with no trip through the queue.What stays the same
publish()are unaffected, and the same service runs standalone whereverlocalis off.Datearrives as its ISO string, a class instance as a plain object,undefinedproperties are dropped andundefinedarray items becomenull, and neither side holds an object of the other's.{ code, message, ... }objects (instanceof Erroris false),callTimeoutapplies, andcallTiming()still splits the call.What differs, on purpose
BigInt, a cycle) rejects at once withIMQ_RPC_CALL_ERROR; through the queue the service failed to send it and the call timed out.multiProcess(aTypeErrorat construction).local: falsesends every call through the queue regardless.How it is found. The registry is anchored on the process (
Symbol.for, as the default option singletons are since 3.5.4), not the module, so a host that loads a service from its own directory, with that service's own copy of this package, still reaches it.localService(),localServiceNames()andwireCopy()are exported for a host.Tests.
test/IMQLocal.spec.ts: no queue send on either side, the JSON semantics, no shared objects, error shapes, unknown method, metadata reaching the method, timing, a BigInt answer, delayed calls andlocal: falsegoing through the queue, the timeout,multiProcessrefused, unregistering ondestroy(), and no signal handlers installed.npm test: 292 pass.Measured (a gateway serving two services in process, the same browser suites against the same images): the round trip to an in-process service fell to under a millisecond at the median and about 2 ms at p95, against 2-20 ms and 30-160 ms through Redis. But the service's own work then shares the caller's event loop, so in that deployment pages got no faster. That is a property of the deployment, not of this transport.