This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-27
Channels
- # announcements (1)
- # aws (17)
- # babashka (2)
- # beginners (14)
- # calva (1)
- # cider (16)
- # clara (1)
- # clj-kondo (68)
- # cljdoc (2)
- # clojure (51)
- # clojure-dev (1)
- # clojure-italy (2)
- # clojure-spec (1)
- # clojure-uk (19)
- # clojurescript (34)
- # cursive (4)
- # fulcro (1)
- # heroku (3)
- # leiningen (36)
- # lumo (28)
- # music (2)
- # off-topic (16)
- # reagent (22)
- # specter (7)
- # sql (7)
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
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
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)
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.
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
yeah--i actually meant “wrong” but didn’t want to say it, but i was wrong for thinking it’s wrong per se.
Yeah, I looked briefly at the source - not enough to fully understand the end result, but in leiningen.core.eval/get-jvm-args
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”
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)