1

So when I start the cloure web application with the command lein ring server, there are 2 processed that get started.enter image description here

The first process is clojur.main that then runs the main web application. The jvm options

:jvm-opts ["-Xmx128m"  "-server"]

for ring work to control the memory for the web application. The issue is that the clojure.main -m leingen.core.main allocates 300+ MB of heap space. (see screenshot 32)

enter image description here

user193116
  • 3,498
  • 6
  • 39
  • 58

3 Answers3

2

well never mind

apparently I should run lein trampoline ring server

This way leingen gets out of the way , saving memory

user193116
  • 3,498
  • 6
  • 39
  • 58
1

The other way is to create a uberjar:

> lein clean
> lein uberjar
Compiling demo.hello
Compiling demo.numbers
Created /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT.jar
Created /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT-standalone.jar

You normally always want to use the xxx-standalone.jar version.

Then you start the process using plain java w/o any lein at all:

java -jar /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT-standalone.jar

and you can add any flags like -Xmx4g or whatever else you like.


Update

I always run lein clean before creating a uberjar. This is the default behavior, but can be disabled by setting :auto-clean false in project.clj. According the the Sample project.clj:

  ; By default Leiningen will run a clean before creating jars to prevent
  ; undeclared AOT from leaking to downstream consumers; this disables
  ; that behaviour.
  :auto-clean false

I cannot see why starting with a dirty build would ever be a good idea, which is why I always manually run lein clean first (just in case :auto-clean has been disabled).

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48
  • 1
    `lein-ring` [suggests that you use `lein ring uberjar`](https://github.com/weavejester/lein-ring#executable-jar-files) rather than just `lein uberjar`. It does mostly the same thing but sets `:auto-clean false`, whatever that means. – amalloy Mar 12 '19 at 19:15
0

You need to set :jvm-opts in your project.clj. e.g.

:jvm-opts ["-Xmx1g" "-server"] 

See also this answer

Simon Brooke
  • 162
  • 2
  • 8