-
Notifications
You must be signed in to change notification settings - Fork 5
Develop #15
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
Develop #15
Conversation
- Added several global middlewares (`beforeOnAck`, `beforeOnReply`, `beforeOnData`, `beforeReply`) that get called before various messages are sent/received - Having these middlewares doesn't increase the overhead of the class that much, and allows for accomplishing some interesting use cases - Use case that we are currently addressing is profiling latencies for commands that are the result of a rocky API request: - 1. The `beforeSend` middleware is used to add a "start" timestamp to the metadata of the message - 2. The `beforeOnData` middleware is used to start time in the form of `hardware.millis()` on the device when the request begins - 3. The `beforeReply` middleware` is used to get the end `hardware.millis()` timestamp to determine the processing time of the request on the device - 4. The `beforeOnReply` handler is used on the Agent to get a final "end" timestamp and to calculate the entire round-trip-time of the request
Add middleware
|
There are a few nuances that will need to be addressed --
|
|
@ppetrosh - let me know what you think. |
|
Also - this includes the change in |
|
Got it, thank you @mm-gmbd! Will review and take it over from here. |
|
@mm-gmbd regarding the |
|
The reason for using the full payload is because that allows additional things to be added to the message (e.g. timestamps as I mentioned above) in the middleware without impacting the |
|
Hi @mm-gmbd, I'm not sure I understand ho Say you have some and access them on the other side as |
|
Can one of the admins verify this patch? |
|
Hey @ppetrosh. Just saw the request for someone to verify this patch and I realized that I never responded to your question last year -- sorry!! I had to re-read the thread in order to remember where everything stood, but to answer your latest question... I think it may be handy to talk through this with a full example. Say I have a message that I want to send from Device->Agent, and then reply to that message from Agent->Device (via the built in MessageManager Now, let's say that, for whatever reason, there is a long delay in sending the message versus getting the response (much longer than the one second delay in the function). As a developer, I want to add some profiling to understand if it's the processing time on the Agent that is accounting for the delay, or if it is network latencies. I can think of two ways to accomplish this: Method A: Add the Profiling to the Implementation ItselfThis is not too big of a problem if there is one and only one message to profile, but in the event that there are multiple messages with different names (which I would assume is most use cases), then the developer has to touch every single line of implementation to add in the profiling, and then has to remove it all to take it back out. Method B: Use Middleware to Implement ProfilingI think with a few optional middlewares, this could be cleaned up immensely and will profile all messages (rather than just the ones that the implementation is updated for). However, I think there are some fundamental differences between my proposed approach (i.e. including the full payload) vs. only exposing the Method B1: Only Expose the
|
|
Another general note -- in |
|
thank you @mm-gmbd for providing the detailed example! a couple of comments:
|
|
That all makes sense.
Can you make the extension and host it in the repository? Maybe with the stipulation that all edge cases haven't been tested and is mainly for debugging purposes at this point? |
|
Yes it probably makes sense to put it inside examples folder under this repository. That's going to show how you can extend the library as needed. |
|
Merging this with mm branch to keep reference to code. At this time there is no plan to merge this feature into a release. |
No description provided.