使用 clojure lein ring 服务器,如何在启动 web 应用程序时设置最大堆大小?
with cloure lein ring server, how to set max heapsize when starting the web appication?
因此,当我使用命令 lein ring server 启动 cloure web 应用程序时,有 2 个处理开始。
第一个进程是 clojur.main,然后运行主 Web 应用程序。 jvm 选项
:jvm-opts ["-Xmx128m" "-server"]
用于环形工作以控制 Web 应用程序的内存。问题是 clojure.main -m leingen.core.main 分配了 300+ MB 的堆 space。 (见屏幕截图 32)
没关系
显然我应该 运行
lein trampoline 环形服务器
这样 leingen 就可以避开,节省内存
另一种方法是创建一个 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
您通常总是希望使用 xxx-standalone.jar
版本。
然后你开始使用普通 java w/o 任何 lein 的过程:
java -jar /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT-standalone.jar
您可以添加任何标志,例如 -Xmx4g
或您喜欢的任何其他内容。
更新
我总是 运行 lein clean
在创建 uberjar 之前。这是默认行为,但可以通过在 project.clj
中设置 :auto-clean false
来禁用。根据样本 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
我不明白为什么从脏构建开始是个好主意,这就是为什么我总是先手动 运行 lein clean
(以防万一 :auto-clean
已被禁用).
您需要在 project.clj
中设置 :jvm-opts
。例如
:jvm-opts ["-Xmx1g" "-server"]
另见 this answer
因此,当我使用命令 lein ring server 启动 cloure web 应用程序时,有 2 个处理开始。
第一个进程是 clojur.main,然后运行主 Web 应用程序。 jvm 选项
:jvm-opts ["-Xmx128m" "-server"]
用于环形工作以控制 Web 应用程序的内存。问题是 clojure.main -m leingen.core.main 分配了 300+ MB 的堆 space。 (见屏幕截图 32)
没关系
显然我应该 运行 lein trampoline 环形服务器
这样 leingen 就可以避开,节省内存
另一种方法是创建一个 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
您通常总是希望使用 xxx-standalone.jar
版本。
然后你开始使用普通 java w/o 任何 lein 的过程:
java -jar /home/alan/expr/demo-horizon/target/demo-horizon-0.1.0-SNAPSHOT-standalone.jar
您可以添加任何标志,例如 -Xmx4g
或您喜欢的任何其他内容。
更新
我总是 运行 lein clean
在创建 uberjar 之前。这是默认行为,但可以通过在 project.clj
中设置 :auto-clean false
来禁用。根据样本 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
我不明白为什么从脏构建开始是个好主意,这就是为什么我总是先手动 运行 lein clean
(以防万一 :auto-clean
已被禁用).
您需要在 project.clj
中设置 :jvm-opts
。例如
:jvm-opts ["-Xmx1g" "-server"]
另见 this answer