16.2. 连接器配置
16.2.1. 为 JBoss EAP 6 里的 HTTP 连接器定义线程池 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
总结
JBoss EAP 6 里的线程池可以通过 Executor 模型在不同组件间共享。这些池不仅可以由不同的 HTTP 连接器共享,也可以被JBoss EAP 6 里支持 Executor 模型的其他组件共享。通过 HTTP 连接器线程池来满足当前的 Web 性能要求是件难办的事,它要求密切监控当前的线程池以及于其的负载需求。在本节里,您会学习如何通过 Executor 模型为 HTTP 连接器设立线程池。您也会学习通过命令行界面或编辑 XML 配置文件来进行设置。
过程 16.1. 为 HTTP 连接器设立线程池
定义线程工厂
打开配置文件standalone.xml(独立服务器)或domain.xml(受管域)。这个文件位于EAP_HOME/standalone/configuration或EAP_HOME/domain/configuration目录。添加下列子系统条目,按照您的服务器的需要修改相关的值。<subsystem xmlns="urn:jboss:domain:threads:1.0"> <thread-factory name="http-connector-factory" thread-name-pattern="HTTP-%t" priority="9" group-name="uq-thread-pool"/> </subsystem>如果您想用 CLI 来完成这个任务,请在 CLI 命令行提示下执行下列命令:[standalone@localhost:9999 /] ./subsystem=threads/thread-factory=http-connector-factory:add(thread-name-pattern="HTTP-%t", priority="9", group-name="uq-thread-pool")创建执行器(Executor)
您可以使用六种内置的 Executor 类来充当这个工厂的执行器。这六种执行器是:unbounded-queue-thread-pool、bounded-queue-thread-pool、blocking-bounded-queue-thread-pool、queueless-thread-pool、blocking-queueless-thread-pool和scheduled-thread-pool。在这个例子里,我们将使用unbounded-queue-thread-pool来充当执行器。修改max-threads和keepalive-time参数的值来满足您的服务器的需要。<unbounded-queue-thread-pool name="uq-thread-pool"> <thread-factory name="http-connector-factory" /> <max-threads count="10" /> <keepalive-time time="30" unit="seconds" /> </unbounded-queue-thread-pool>或者您更愿意使用 CLI:[standalone@localhost:9999 /] ./subsystem=threads/unbounded-queue-thread-pool=uq-thread-pool:add(thread-factory="http-connector-factory", keepalive-time={time=30, unit="seconds"}, max-threads=30)让 HTTP 连接器使用这个线程池
在相同的配置文件里,找到 web 子系统下的 HTTP 连接器元素并进行修改,让它使用之前步骤里定义的线程池。<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="uq-thread-pool" />或者您更愿意使用 CLI:[standalone@localhost:9999 /] ./subsystem=web/connector=http:write-attribute(name=executor, value="uq-thread-pool")重启服务器
重启服务器(独立服务器或受管域)让修改可以生效。请用下列 CLI 命令来确认上面步骤里的修改已经生效:[standalone@localhost:9999 /] ./subsystem=threads:read-resource(recursive=true) { "outcome" => "success", "result" => { "blocking-bounded-queue-thread-pool" => undefined, "blocking-queueless-thread-pool" => undefined, "bounded-queue-thread-pool" => undefined, "queueless-thread-pool" => undefined, "scheduled-thread-pool" => undefined, "thread-factory" => {"http-connector-factory" => { "group-name" => "uq-thread-pool", "name" => "http-connector-factory", "priority" => 9, "thread-name-pattern" => "HTTP-%t" }}, "unbounded-queue-thread-pool" => {"uq-thread-pool" => { "keepalive-time" => { "time" => 30L, "unit" => "SECONDS" }, "max-threads" => 30, "name" => "uq-thread-pool", "thread-factory" => "http-connector-factory" }} } } [standalone@localhost:9999 /] ./subsystem=web/connector=http:read-resource(recursive=true) { "outcome" => "success", "result" => { "configuration" => undefined, "enable-lookups" => false, "enabled" => true, "executor" => "uq-thread-pool", "max-connections" => undefined, "max-post-size" => 2097152, "max-save-post-size" => 4096, "name" => "http", "protocol" => "HTTP/1.1", "proxy-name" => undefined, "proxy-port" => undefined, "redirect-port" => 443, "scheme" => "http", "secure" => false, "socket-binding" => "http", "ssl" => undefined, "virtual-server" => undefined } }
结果
您已经创建一个线程工厂和执行器,而且修改了 HTTP 连接器来使用这个线程池。