leiningen

N.B. The maintainers are on #leiningen on Libera chat IRC. Go there for direct support/bug reports.
zlrth 2019-10-27T16:16:14.023400Z

I’m calling a function from the commandline like so:

JVM_OPTS="-Xmx8G" lein run -m myproject/myfunction
it’s out-of-memory’ing, no matter what i set Xmx to. looking a little more, I see via jps -lv that the process being called looks like:
26548 clojure.main -Dfile.encoding=UTF-8 -Xmx8G -Xmx4g -Dclojure.compile.path=/home/app/myproject/target/classes -Dcollage.version=0.1.0-SNAPSHOT -Dclojure.debug=false
note the two Xmx flags. my java program is taking the second Xmx value. (i get the same results as this SO commenter[0]) the -Xmx4g comes from my project.clj (or at least, that’s only place Xmx4g appears i can find). looking at the tutorial, I’d say that JVM_OPTS should overwrite a project.clj’s :jvm-opts[1]. [0] https://stackoverflow.com/a/26727332/3925569 [1] https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#setting-jvm-options

zlrth 2019-10-27T16:30:29.026600Z

this open github issue[0] marked for the 3.0.0 release speaks to my behavior. this indicates to me that i should not expect an environment variable will override project configuration. ok. how do i set an -Xmx on a per-invocation basis? [0] https://github.com/technomancy/leiningen/issues/1680

2019-10-27T19:54:41.027200Z

@mfm per-invocation: how about

lein update-in : assoc :jvm-opts '["-Xmx8G"]' -- run -m myproject/myfunction

2019-10-27T19:55:15.027700Z

alternatively, you could make a :profiles entry that set :jvm-opts when a certain profile was used via with-profile

2019-10-27T19:55:26.028100Z

you could also add an :aliases entry to do something like above if you knew it was a common case

2019-10-27T19:57:18.030100Z

you could also avoid having the project have a default :jvm-opts by moving the project’s own :jvm-opts (of 4g as you say above), to a profile, and only have that profile active via a certain :aliases so that it doesn’t interfere with someone just wanting to use JVM_OPTS w/ lein run

2019-10-27T19:58:27.031500Z

I typo’ed my update-in above too, will fix - fixed

zlrth 2019-10-27T19:59:14.032700Z

ah--thanks for lein update-in. trying that now. should have added this context: in production and staging, we happen to use lein run -m myproject/myfunction for basically scripts. so i’d like to have per-invocation setting of xmx for those calls, because the amount of ram they should have differs, both from each other and from project.clj

zlrth 2019-10-27T19:59:33.033400Z

(not to correct anything you’re saying; what you’re saying is compatible)

2019-10-27T19:59:47.033700Z

yeah, makes sense

2019-10-27T19:59:57.033900Z

update-in may be what you want

2019-10-27T20:00:08.034300Z

there may be an issue of profile merging still, if so, have to probably make it uglier

👍 1
2019-10-27T20:00:24.034700Z

lein update-in : assoc :jvm-opts '^:replace ["-Xmx8G"]' -- run -m myproject/myfunction

2019-10-27T20:00:58.035600Z

or probably better yet, in your project.clj where you have :jvm-opts, do ^:displace metadata instead. I may be wrong, can’t remember. update-in may not try to merge when you do assoc (now that I think of it, I don’t recall ever seeing a merging issue like I’m bringing up here)

zlrth 2019-10-27T20:01:20.036Z

thanks! i can try out some different things

👍 1
2019-10-27T20:02:05.037Z

yep, let me know if things don’t work out

zlrth 2019-10-27T20:02:10.037200Z

sanity check: am i correct that the tutorial is misleading? > You can also pass options to Leiningen in the JVM_OPTS environment variable. https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#setting-jvm-options

2019-10-27T20:02:21.037700Z

you can also add DEBUG=true lein ... to sometimes get some more verbose details of what is happening.

zlrth 2019-10-27T20:02:27.037900Z

oh nice--thanks

2019-10-27T20:03:24.038600Z

The line > You can also pass options to Leiningen in the JVM_OPTS environment variable. is perhaps just too vague if I understand the problem correctly - that JVM_OPTS takes “lower priority” than project :jvm-opts

zlrth 2019-10-27T20:03:50.039Z

ah yeah

2019-10-27T20:03:53.039200Z

I assume that’s what you are referring to by “misleading” right?

2019-10-27T20:04:10.039900Z

I think JVM_OPTS do work when you don’t have :jvm-opts though.

zlrth 2019-10-27T20:04:32.040200Z

yeah--i actually meant “wrong” but didn’t want to say it, but i was wrong for thinking it’s wrong per se.

zlrth 2019-10-27T20:05:11.041100Z

i now see that that they don’t specify priority

2019-10-27T20:07:00.041800Z

Yeah, I looked briefly at the source - not enough to fully understand the end result, but in leiningen.core.eval/get-jvm-args

2019-10-27T20:07:29.042400Z

so it reads both there, how that works out beyond there is a bit unclear still

2019-10-27T20:07:53.042700Z

if you use DEBUG=true may be clearer. I almost wonder if we end up with like java -Xmx8g ... -Xmx4g ... and that just is JVM dependent

2019-10-27T20:09:49.044100Z

think they are stored in some sort of hash-map in JVM typically, wher the 2nd one read tends to “win”

2019-10-27T20:10:06.044600Z

but at this point - just hypothesizing, so will quit while ahead 😵

zlrth 2019-10-27T20:10:42.045400Z

thank you very much!

zlrth 2019-10-27T20:11:18.046100Z

this:

lein update-in : assoc :jvm-opts '^:replace ["-Xmx8G"]' -- run -m myproject/myfunction
works for me (for anyone reading, i added a - in front of Xmx)

🎉 1
zlrth 2019-10-27T20:11:54.046900Z

“works” means “the output of jps looks right” and i’ll post again in celebration if the function doesn’t OOM

zlrth 2019-10-27T20:11:56.047100Z

thanks again!

2019-10-27T20:12:25.047500Z

ah dang - when I edited didn’t have the lead - sorry

👍 1
zlrth 2019-10-27T20:12:36.047800Z

no problem!