【问题标题】:How to increase Jetty threadpool size with jetty-runner on Heroku?如何在 Heroku 上使用 jetty-runner 增加 Jetty 线程池大小?
【发布时间】:2013-04-11 14:48:06
【问题描述】:

我有一个在 Heroku 上运行的 Java (Spring MVC) webapp。它使用本文中描述的设置: Getting Started with Spring MVC Hibernate on Heroku

看起来 Jetty 默认只使用一个线程。鉴于此 Heroku 和 jetty-runner 设置,增加线程池大小的最简单方法是什么

注意:我没有任何自定义 Jetty 相关代码(因此不清楚我将如何应用这些建议,例如:How to use setThreadPool() in Jetty)。如果可能的话,我宁愿保持这种状态。所有与 Jetty 相关的内容现在都在 Procfile 和 pom.xml 中(见下文)。

我可以使用一些 jetty-runner 参数或配置选项来设置线程池大小吗?如果我需要创建一个 Jetty 配置文件,如何让 Heroku/jetty-runner 使用它?

过程文件:

web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war

pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.7</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>copy</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>jetty-runner</artifactId>
                        <version>8.1.10.v20130312</version>
                        <destFileName>jetty-runner.jar</destFileName>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

【问题讨论】:

标签: java spring heroku jetty threadpool


【解决方案1】:

为我解决了什么问题(Spring,而不是 Jetty 问题)

当我在问题中写这个时我错了:

看起来 Jetty 默认只使用一个线程。

结果证明这纯粹是一个 Spring 问题。在applicationContext.xml中,我改了

<task:annotation-driven/>

进入

<task:annotation-driven scheduler="scheduler-pool"/>
<task:scheduler id="scheduler-pool" pool-size="5"/>

...和不同的@Scheduled 任务现在可以愉快地在单独的线程中运行,例如scheduler-pool-1scheduler-pool-3

如何调整 Jetty 线程池配置(使用 jetty-runner)

(在我意识到我的问题不是一个 Jetty 问题之前,我已经研究了如何配置 Jetty 线程池。在这里记录一下;也许它对某人有用。)支持>

创建一个jetty.xml config file(类似于src/main/resources,以便将其复制到编译目标目录),并根据自己的喜好对其进行自定义。

示例(可能是一个糟糕的例子):

<?xml version="1.0"?>

<!-- For some reason, must use org.eclipse classes, 
 even though we depend on org.mortbay Jetty... -->

<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <Set name="ThreadPool">
        <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
            <Set name="minThreads">3</Set>
            <Set name="maxThreads">5</Set>
        </New>
    </Set>

</Configure>

然后,告诉 jetty-runner 使用带有 --config 开关的配置文件。所以例如在 Heroku 的Procfile 中,添加--config target/classes/jetty.xml

web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --config target/classes/jetty.xml --port $PORT target/*.war 

如果您也碰巧使用 jetty-maven-plugin,您可以通过在 &lt;configuration&gt; 下的 pom.xml 中添加以下内容来告诉它使用您的自定义 Jetty 配置:

<jettyConfig>target/classes/jetty.xml</jettyConfig>

【讨论】:

  • 线程池中最大连接数的默认大小只有1?真的吗?
  • @Luke,您可以在 /etc/jetty.xml 中找到相对于 jetty 目录的默认最小/最大线程池大小。 10/200 是默认值
猜你喜欢
  • 1970-01-01
  • 2013-09-03
  • 1970-01-01
  • 2012-10-17
  • 1970-01-01
  • 2021-10-31
  • 1970-01-01
  • 2012-06-24
  • 1970-01-01
相关资源
最近更新 更多