Closed christhekeele closed 3 years ago
The main sensitive issue I forsee is sampling of timing data impacting performance of Mojito
itself.
I don't think several System.monotonic_time
measurements and a few System.convert_time_unit
/Integer.to_string
calls would make a huge difference. Plug
itself
makes similar calls in its Logger
.
But both Logger
and Plug
purge such unnecessary calls in production environments via macros, so perhaps a similar Mojito
mechanism should do the same?
Hi @christhekeele! Thanks for the feature request. I think the best way to implement this would be to accept a timing: true
config option in Mojito.request
, and add timing information as a new field in the returned %Mojito.Response{}
. My gut feeling is that implementing this in terms of macros won't be necessary; it would certainly be less flexible if we did.
Coming back on this: the Telemetry library is gaining acceptance as a way to publish this sort of timing information. I will be adding this to Mojito.
Is there any way to config proxy
in config.exs
for Mojito ?
Or is there any hook like init for Ecto
to define proxy for Mojito?
Hey @collegeimprovements! Just to clarify here, Mojito
is not responsible for any sort of proxy functionality.
I was building my own proxy on top of Mojito
when I started this discussion, and brought that up as a use-case.
@gamache I spent a little time tinkering with a PR for this tonight and realized that most of the telemetry I personally am interested in may more sense in Mint
rather than Mojito
itself. Specifically, events like:
[:mojito, :connection, :established], %{timestamp, duration}, %Mojito.Conn{}
[:mojito, :connection, :closed], %{timestamp}, %Mojito.Conn{}
[:mojito, :request, :initiated], %{timestamp}, %Mojito.Request{} + request_ref
[:mojito, :request, :done], %{timestamp}, %Mojito.Request{} + request_ref
[:mojito, :request, :performed], %{duration}, %Mojito.Request{} + request_ref
I think Mint
could emit most of those itself. I'll probably poke through it more to think about where these things belong.
Stepping back from my own needs, though, I can also see the value in pooling telemetry, since that is a major value-add of Mojito
. Maybe events like:
[:mojito, :pool, :started]
[:mojito, :pool, :full]
[:mojito, :request, :done]
I'm not sure if these are the sorts of things you have in mind, too. If you're accepting contributions, I'd enjoy discussing what sort of events you think belong in Mojito
and submitting a :telemetry
-enabling PR along those requirements. Otherwise, I appreciate you entertaining this feature request. Either way, thanks for the work on Mojito
!
@christhekeele how does https://github.com/appcues/mojito/pull/81 look to you?
@andyleclair that looks brilliant, exactly what I needed!
Closing this as it is resolved in 0.7.7
Playing around with an HTTP forward-proxy powered by Mojito. One question I keep asking myself: how much overhead am I adding?
Round trip time
The consumers of my service, of course, can sample their language equivalent of
System.monotonic_time()
immediately before and after the request. I would like to provide them with a number to subtract from the result to understand the overhead.Proxy spent time
My proxy could sample the same, right after receiving and right before returning the response for, the proxied request.
Proxy waiting time
It could also figure out how long requests took outside of its own logic via the same mechanism, by tightly wrapping Mojito calls in timing measurements.
External waiting time
The main metric I am interested in that I cannot obtain is how long Mojito itself spent waiting for the upstream to respond.
I would like to return the time spent outside the proxy to the caller, but I can't do this without knowing how long Mojito itself was blocked, since I want to incorporate time spent in Mojito into the time spent in the proxy, and separate it (as much as possible) from the external time spent waiting for the request to be processed.
The only way I can see this working is having Mojito aggregate the time spent waiting for connection responses from Mint, and return the sum once the request is completed to the caller of
Mojito.request
.Any thoughts about how this could work to guide a PR?