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-optionsthis 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
@mfm per-invocation: how about
lein update-in : assoc :jvm-opts '["-Xmx8G"]' -- run -m myproject/myfunction
alternatively, you could make a :profiles
entry that set :jvm-opts
when a certain profile was used via with-profile
you could also add an :aliases
entry to do something like above if you knew it was a common case
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
I typo’ed my - fixedupdate-in
above too, will fix
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
(not to correct anything you’re saying; what you’re saying is compatible)
yeah, makes sense
update-in
may be what you want
there may be an issue of profile merging still, if so, have to probably make it uglier
lein update-in : assoc :jvm-opts '^:replace ["-Xmx8G"]' -- run -m myproject/myfunction
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)
thanks! i can try out some different things
yep, let me know if things don’t work out
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
you can also add DEBUG=true lein ...
to sometimes get some more verbose details of what is happening.
oh nice--thanks
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
ah yeah
I assume that’s what you are referring to by “misleading” right?
I think JVM_OPTS
do work when you don’t have :jvm-opts
though.
yeah--i actually meant “wrong” but didn’t want to say it, but i was wrong for thinking it’s wrong per se.
i now see that that they don’t specify priority
Yeah, I looked briefly at the source - not enough to fully understand the end result, but in leiningen.core.eval/get-jvm-args
so it reads both there, how that works out beyond there is a bit unclear still
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
think they are stored in some sort of hash-map in JVM typically, wher the 2nd one read tends to “win”
but at this point - just hypothesizing, so will quit while ahead 😵
thank you very much!
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)“works” means “the output of jps looks right” and i’ll post again in celebration if the function doesn’t OOM
thanks again!
ah dang - when I edited didn’t have the lead -
sorry
no problem!