How do I set jvm options for a lein repl

7,875 views
Skip to first unread message

Larry Travis

unread,
May 21, 2012, 12:51:34 AM5/21/12
to clo...@googlegroups.com, Larry Travis
How do I set jvm options for a lein repl initiated independently of a project?   In particular, I want the heap expansion that results from doing "M-x clojure-jack-in" in an emacs project.clj buffer with ":jvm-opts [ "-Xms4G" "-Xmx4G"]" in its defproject form.
  --Larry

Raju Bitter

unread,
May 21, 2012, 7:19:59 AM5/21/12
to clo...@googlegroups.com
Check the sample project.clj on Github:
https://github.com/technomancy/leiningen/blob/master/sample.project.clj

There's an entry for JVM options:

;; You can set JVM-level options here.
:jvm-opts ["-Xmx1g"]

In a quick test, that worked for me when lein repl was executed.

- Raju

Raju Bitter

unread,
May 21, 2012, 7:37:12 AM5/21/12
to clo...@googlegroups.com
Oh, sorry, misunderstood your question. I found this blog post, maybe
this still works, although it's from 2010:
http://www.clojurepla.net/2010/05/increase-jvm-memory-when-using-swank.html

Moritz Ulrich

unread,
May 21, 2012, 7:46:23 AM5/21/12
to clo...@googlegroups.com
That blog post is pretty outdated. When using leiningen, you can pass
arbitrary jvm opts via project.clj[1]:

:jvm-opts ["-Xmx1g"]

[1]: https://github.com/technomancy/leiningen/blob/master/sample.project.clj
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



--
Moritz Ulrich

Raju Bitter

unread,
May 21, 2012, 8:28:14 AM5/21/12
to clo...@googlegroups.com
Larry is looking for a way to set that value across all projects, not
just for one project.

- Raju

Roberto Mannai

unread,
May 21, 2012, 8:52:38 AM5/21/12
to clo...@googlegroups.com
You could add the following evinroment variable to your OS:
LEIN_JVM_OPTS=-Xms4G -Xmx4G

On Windows for example, you could add at the top of "lein.bat" file the following line (under "@echo off"):
SET LEIN_JVM_OPTS=-Xms4G -Xmx4G

This should be enough to do the trick.


On Mon, May 21, 2012 at 6:51 AM, Larry Travis <tra...@cs.wisc.edu> wrote:
How do I set jvm options for a lein repl initiated independently of a project?   In particular, I want the heap expansion that results from doing "M-x clojure-jack-in" in an emacs project.clj buffer with ":jvm-opts [ "-Xms4G" "-Xmx4G"]" in its defproject form.
  --Larry

--

Mikhail Kryshen

unread,
May 21, 2012, 12:04:17 PM5/21/12
to Clojure
Also there is an environment variable _JAVA_OPTIONS (note the leading
underscore) which is handled by the HotSpot JVM (OpenJDK or Oracle
JDK) and can be used with any java application.

--
Mikhail

Phil Hagelberg

unread,
May 21, 2012, 12:42:24 PM5/21/12
to clo...@googlegroups.com
You can set :jvm-opts in the user profile if you're using Leiningen 2.
Otherwise set JVM_OPTS as an environment variable.

-Phil

Larry Travis

unread,
May 21, 2012, 5:55:14 PM5/21/12
to clo...@googlegroups.com, Larry Travis
I should be switching over to Leiningen 2 shortly in any case, but I am
curious. How does one "set JVM_OPTS as an environment variable"?
--Larry

Softaddicts

unread,
May 21, 2012, 6:15:17 PM5/21/12
to clo...@googlegroups.com
If you are running in a unix shell, something like

JVM_OPTS=-Xms4G ...

Followed by
export JVM_OPTS

Bash allows you to combine the two as in:

export JVM_OPTS-Xms4G ...

In a windows Cmd shell, something like this should work:

set JVM_OPTS=Xms4G ...

before running lein from the command line.

Luc
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
--
Softaddicts<lprefo...@softaddicts.ca> sent by ibisMail from my ipad!

Softaddicts

unread,
May 21, 2012, 7:16:34 PM5/21/12
to clo...@googlegroups.com
The bash example is

export JVM_OPTS=-Xms4G ...

missed the = ...

Luc

Larry Travis

unread,
May 22, 2012, 1:29:29 AM5/22/12
to clo...@googlegroups.com, Larry Travis
It took me a while to figure out how to put multiple entries into an
environment variable (that is, settings for both min and max heap sizes,
to wit, "export JVM_OPTS=\ -Xms4G\ -Xmx4G") but, once I did, Phil's and
Luc's suggestions have worked well and things have gone swimmingly. They
work for both bash and eshell. Thanks much to you all.
--Larry

Larry Travis

unread,
Jul 8, 2012, 5:13:24 PM7/8/12
to clo...@googlegroups.com, Larry Travis
(1) Is there any way I can extract from a Clojure lazy sequence at some
given point in its use those of its members that have so far been
realized? For example, can I extract the cache of realized members, turn
it into a vector, and then process that vector independently of further
use of the lazy sequence?

(2) If I can't extract the cache, is there some way that I can at least
discover how many realized sequence members have so far been put into
the cache?

It is obvious that, if all I want is an initial segment of a lazy
sequence, I can force the initial segment's realization and get hold of
it for further processing (independent of its source) with the take
function -- but I want to know how many and what members of the lazy
sequence have so far been realized independently of my forcing their
realization -- for example, in order to evaluate and compare success so
far of alternative solution paths being simultaneously pursued by an AI
algorithm.

Thanks in advance for any relevant advice.
--Larry

Tassilo Horn

unread,
Jul 9, 2012, 2:44:18 AM7/9/12
to clo...@googlegroups.com, Larry Travis
Larry Travis <tra...@cs.wisc.edu> writes:

Hi Larry,

> (1) Is there any way I can extract from a Clojure lazy sequence at
> some given point in its use those of its members that have so far been
> realized? For example, can I extract the cache of realized members,
> turn it into a vector, and then process that vector independently of
> further use of the lazy sequence?

I think, you are looking for `realized?`. Here's a function for
creating a vector of realized elements of a lazy seq.

--8<---------------cut here---------------start------------->8---
user> (defn realized-vec [s]
(loop [s s, r []]
(if (and (seq s) (realized? (rest s)))
(recur (rest s) (conj r (first s)))
(conj r (first s)))))
#'user/realized-vec
user> (def nums (iterate inc 0))
#'user/nums
user> (realized-vec nums)
[0]
user> (take 10 nums)
(0 1 2 3 4 5 6 7 8 9)
user> (realized-vec nums)
[0 1 2 3 4 5 6 7 8 9]
user> (take 15 nums)
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14)
user> (realized-vec nums)
[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
--8<---------------cut here---------------end--------------->8---

One thing I don't quite understand is why you cannot call `realized?` on
all sequential things. For example, `iterate` is documented to return a
lazy seq, but in fact it creates a Cons whose rest is a lazy seq. Thus,
calling `realized?` on its result errors.

--8<---------------cut here---------------start------------->8---
user> (realized? (iterate inc 1))
; clojure.lang.Cons cannot be cast to clojure.lang.IPending
; [Thrown class java.lang.ClassCastException]
--8<---------------cut here---------------end--------------->8---

So my question is: shouldn't all sequential collections implement
IPending (simply returning true in the case of lists, cons, vector,
...)? Or should `realized?` also test for IPending?

> (2) If I can't extract the cache, is there some way that I can at
> least discover how many realized sequence members have so far been put
> into the cache?

With the function above, that's (comp count realized-vec).

Bye,
Tassilo

Tassilo Horn

unread,
Jul 9, 2012, 3:24:25 AM7/9/12
to clo...@googlegroups.com, Larry Travis
Tassilo Horn <tas...@member.fsf.org> writes:

> I think, you are looking for `realized?`. Here's a function for
> creating a vector of realized elements of a lazy seq.
>
> user> (defn realized-vec [s]
> (loop [s s, r []]
> (if (and (seq s) (realized? (rest s)))
> (recur (rest s) (conj r (first s)))
> (conj r (first s)))))

Another note: the (seq s) call for testing if the seq is exhausted [and
also the (rest s) call] will force the realization of the current item.
As a result, the function will at least realize one element, although
the given lazy seq may be completely unrealized.

Here's a better version that doesn't force realization.

--8<---------------cut here---------------start------------->8---
user> (defn my-realized? [s]
(or (not (instance? clojure.lang.IPending s))
(realized? s)))

(defn realized-vec [s]
(loop [s s, r []]
(if (and (my-realized? s) (seq s))
(recur (rest s) (conj r (first s)))
r)))

(def nums (iterate inc 0))
#'user/nums
user> (realized-vec nums)
[0]
user> (take 10 nums)
(0 1 2 3 4 5 6 7 8 9)
user> (realized-vec nums)
[0 1 2 3 4 5 6 7 8 9]
user> (def r (range))
#'user/r
user> (realized-vec r)
[]
user> (take 5 r)
(0 1 2 3 4)
user> (realized-vec r)
[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31]
--8<---------------cut here---------------end--------------->8---

Note that `range` returns a so-called chunked lazy seq, where
realization always happens is chunks of 32 elements.

Bye,
Tassilo
Reply all
Reply to author
Forward
0 new messages