Any thoughts on how to really know on middleware side how much time took from REPL start trigger to really become available to user?
I tried (.getUptime (ManagementFactory/getRuntimeMXBean)) suggestion from @jpmonettas but it's not even close to the real time, I'm getting it on the first op received (clone).
Testing with a project that takes 39s to repl become ready to use, it returns 19s which doesn't seem right
not sure lein could be affecting there as it starts a new JVM or so, thinking that will be hard to know unless clients provide that time from their side
Not out of the box. You can monkey-patch start-server (https://github.com/nrepl/nrepl/blob/47aa27b52d09ea5636272d8b93ba68a3824c808d/src/clojure/nrepl/server.clj#L178) to record the timestamp once it finishes loading and subtract it from the JVM starting time.
hum, you mean under the hood this function will always be called and I can kind of wrap it to get the time?
Yeah. But wrapping it by monkey-patching might be somewhat tricky. You want the patch to happen before the server is started
> not sure lein could be affecting there as it starts a new JVM or so Yeah, lein uses two JVMs, so it may be the reason
even so, that wouldn't help I guess, I want the time the user took waiting for the repl to be available, besides the lein JVM issue, getting the time start-server was called seems to not ideal as stuff happened before for that to happen
You can wrap your test running function on the bash side in a script that puts the startup timestamp onto the env
JVM_STARTING_TIME=$(date +%s) lein ...
Then inside the process subtract the current timestamp from that value – gives you "real" time from start
haha yah, but I'd love to fix that in a good way as this is one of the features of https://github.com/ericdallo/metrepl that I'm building
Then .getUptime is the best you have. Of course, it cannot know if the build tools and everything was fooling around for minutes before they finally started this jvm
yeah, I was thinking how feasible would be to accept a request-timestamp in clonerequest:see_no_evil:
that would basically solve all lein time issues, although needs PRs on most editors (but I did that recently so I'm ok with that )
Not sure what this will give you
The client doesn't send clone until it connects to the server
You need a live socket for that
The socket won't be available until the server starts
ah true
I mean
yeah, each client would need to store the timestamp in memory of when started the repl command and then pass that on clone request when happen
kinda tricky
"Time until REPL starts" from the strictly-client perspective only makes sense for the client that is also the initializer of the server. This is a partial case of nrepl usage but not a generic one.
yeah, indeed
I wish there was a way to solve that
> yeah, each client would need to store the timestamp in memory of when started the repl command
STARTUP_TIMESTAMP=$(date.. 😂
yeah true haha
Again, it seems you are trying to solve too broad of an issue
You can measure the time from JVM start to REPL being alive, and that will be generic
But it won't account for all the prior stuff that happens around that JVM (build tools, maybe downloading dependencies, who knows). And I doubt that REPL/nrepl/middleware can/should know about that
People who want to know this information can solve it for their particular setups, but that won't be generic for sure
good point
thanks for the inputs
@ericdallo yeah, lein start two JVMs and that is probably the difference. Have you tried lein trampoline, I think that should do it with one JVM