Jetty 9 忽略我的配置 XML

标签 jetty embedded-jetty

我在一个项目中使用 Jetty-Runner,最近升级到 Jetty 9。使用新配置迁移 XML 后,我在启动日志中注意到以下行:

WARN:oejx.XmlConfiguration:main: Ignored arg: ...

被打印的被忽略的arg几乎是我的整个XML,它是:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"     
"http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Arg name="threadpool">
    <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
      <Arg name="maxThreads">200</Arg>
      <Arg name="minThreads">50</Arg>
      <Arg name="idleTimeout">1000</Arg>
      <Arg name="queue">
        <New class="java.util.concurrent.ArrayBlockingQueue">
          <Arg type="int">6000</Arg>
        </New>
      </Arg>
      <Set name="detailedDump">false</Set>
    </New>
  </Arg>
</Configure>

我已经使用当前的 Jetty Javadocs 检查了每个参数名称/类型/ setter ,但仍然无法理解此设置有什么问题,可以忽略。

你能帮忙吗?

最佳答案

更新:2018 年 2 月

Ignored arg:意味着您有 <Arg>未用于 <Configure> 中引用的对象的构造函数(或<New>)。最可能的原因是您正在尝试更改之前已经设置的内容。

如果您在这里是因为想要更改线程池,请继续阅读。

如果您只想配置QueuedThreadPool ,你有选择。

The Recommended Choice: Using the jetty-home or jetty-distribution to start Jetty? Configure the threading property values in your ${jetty.base} directory. You can find them either in your ${jetty.base}/start.ini or ${jetty.base}/start.d/*.ini files.

不使用jetty-homejetty-distribution ,但仍然使用 XML? 为什么?(真的,我们想知道!)

XML <Get>方法最好是在现有线程池上设置值。

示例( from Jetty 9.2.20 ,相同 as Jetty 9.4.8 ):

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

...

    <Get name="ThreadPool">
      <Set name="minThreads" type="int">10</Set>
      <Set name="maxThreads" type="int">200</Set>
      <Set name="idleTimeout" type="int">60000</Set>
      <Set name="detailedDump">false</Set>
    </Get>

If you want to change from QueuedThreadPool to something else, this is considered an extreme expert level option. You have to be aware of the impact this will have on your server.

更改最小/最大线程时,请注意以下事项:

  • 您拥有的 CPU 核心数量。 (这会影响所需的最少线程)
  • 您拥有的网络接口(interface)数量。 (这会影响所需的最少线程)
  • 您将拥有的同时连接数。 (这会影响所需的最少线程)
  • 您将同时处理的请求数。 (这会影响所需的最少线程)
  • 使用 HTTP/2 会显着增加您的线程要求。
  • 使用老式 Servlet 阻塞 API 会增加您的线程要求。 (考虑使用较新的 AsyncContext 和异步 I/O 行为,它将显着降低您的线程要求)

一些最小线程示例:

The following examples are for illustration purposes and do not represent a "recommended" set of values from the Jetty project. The Jetty recommended values are the default values already present in Jetty.

在 Intel i7 上,具有 1 个网络接口(interface),服务于普通网页,包含资源(图像、CSS、JavaScript 等)。您至少需要大约 22 个线程(8 个用于 CPU 核心,1 个用于网络接口(interface),1 个用于接受器,1 个用于选择器,以及大约 10 个用于为典型的现代 Chrome 浏览器提供网页及其资源)。

在具有 1 个网络接口(interface)的 Raspberry Pi 上,按顺序向单个 REST 客户端提供 REST 请求(从不并行),您至少需要 8 个线程。

更多注释:

此外,不要假设 1 个线程 == 1 个请求/响应交换。 Jetty 上情况并非如此。单个请求/响应交换可以在其生命周期内由 [1...n] 个线程处理。只有使用旧式 Servlet API 的阻塞读/写才会保留线程(再次使用新的 Servlet API 异步 I/O 操作)

如果您想在减少 Jetty 上某些内容的流量/请求的假设下调整线程配置,请考虑使用 QoSFilter (用于控制端点/资源特定行为)或 DoSFilter (用于控制总体负载限制)。

旧答案(2013 年 12 月起)

1) 修复 DTD

你的:

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"     
"http://www.eclipse.org/jetty/configure.dtd">

Jetty 9+ 的正确选择

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" 
"http://www.eclipse.org/jetty/configure_9_0.dtd">

2) 使用type属性更好

type="int"旧版本的 Jetty 不支持,如 "int"不是有效的对象类型。使用java.lang.Integer相反(或升级到支持 "int" 的较新版本的 Jetty)

试试这个。

<Arg name="threadpool">
  <New id="threadpool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
    <Arg type="java.lang.Integer" name="maxThreads">200</Arg>
    <Arg type="java.lang.Integer" name="minThreads">50</Arg>
    <Arg type="java.lang.Integer" name="idleTimeout">1000</Arg>
    <Arg name="queue">
      <New class="java.util.concurrent.ArrayBlockingQueue">
        <Arg type="java.lang.Integer">6000</Arg>
      </New>
    </Arg>
    <Set name="detailedDump">false</Set>
  </New>
</Arg>

以上内容已通过 jetty-9.1.0.v20131115 验证分布。

关于Jetty 9 忽略我的配置 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20472245/

相关文章:

java - 无法在 Windows 7 中运行 jetty-maven-plugin

java - 如何将 jar 放在 jetty 类路径的 jetty/lib 中?

java - Jersey Jetty Embedded 无法读取路径注释,错误 404

java - 带有嵌入式 Jetty 服务器的 Jersey

ldap - 如何配置嵌入式 Jetty 以使用 LdapLoginModule?

java - 无效的 END header (错误的中央目录大小)zipException

java - 带有嵌入式 Jetty 的 Jersey 解决资源中的依赖注入(inject)

java - 使用 Maven 部署带有嵌入式 jetty 的 jar

java - Web Socket 上传文件并在同一端点上发送 json

java - Jetty 9 与 Spring 2 兼容性