undertow

SpringBoot使用Undertow做服务器

好久不见. 提交于 2019-12-02 03:06:29
说明 undertow,jetty和tomcat可以说是javaweb项目当下最火的三款服务器,tomcat是apache下的一款重量级的服务器,不用多说历史悠久,经得起实践的考验。然而:当下微服务兴起,spring boot ,spring cloud 越来越热的情况下,选择一款轻量级而性能优越的服务器是必要的选择。spring boot 完美集成了tomcat,jetty和undertow,本文将通过对jetty和undertow服务器的分析以及测试,来比较两款服务器的性能如何。   值得一提的是jetty和undertow都是基于NIO实现的高并发轻量级的服务器,支持servlet3.1和websocket。所以,有必要先了解下什么是NIO。 NIO(非阻塞式输入输出) Channel Selector Buffer Acceptor    Client和Server只向Buffer读写数据不关注数据的流向,数据通过Channel通道进行流转。而Selector是存在与服务端的,用于Channel的注册以此实现数据I/O操作。Acceptor负责接受所以的连接通道并且注册到Channel中。而整个过程客户端与服务端是非阻塞的也就是异步操作。 下面是压力测试对比图: 服务器 命中 成功率 吞吐量 平均耗时 Jetty 11488 100% 96.25 trans/sec 0

Undertow

人盡茶涼 提交于 2019-12-01 23:34:13
Spring Boot 内嵌容器Undertow参数设置 配置项: # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 # 不要设置过大,如果过大,启动项目会报错:打开文件数过多 server.undertow.io-threads=16 # 阻塞任务线程池, 当执行类似servlet请求阻塞IO操作, undertow会从这个线程池中取得线程 # 它的值设置取决于系统线程执行任务的阻塞系数,默认值是IO线程数*8 server.undertow.worker-threads=256 # 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理 # 每块buffer的空间大小,越小的空间被利用越充分,不要设置太大,以免影响其他应用,合适即可 server.undertow.buffer-size=1024 # 每个区分配的buffer数量 , 所以pool的大小是buffer-size * buffers-per-region server.undertow.buffers-per-region=1024 # 是否分配的直接内存(NIO直接分配的堆外内存) server.undertow.direct-buffers=true 来看看源代码: https://github.com

How to properly read POST request body in a Handler?

試著忘記壹切 提交于 2019-12-01 16:13:19
The code I'm using now: Pooled<ByteBuffer> pooledByteBuffer = exchange.getConnection().getBufferPool().allocate(); ByteBuffer byteBuffer = pooledByteBuffer.getResource(); int limit = byteBuffer.limit(); byteBuffer.clear(); exchange.getRequestChannel().read(byteBuffer); int pos = byteBuffer.position(); byteBuffer.rewind(); byte[] bytes = new byte[pos]; byteBuffer.get(bytes); String requestBody = new String(bytes, Charset.forName("UTF-8") ); byteBuffer.clear(); pooledByteBuffer.free(); It seems to work OK but I'm not sure about the need to clear() ByteBuffer before returning it to the pool. I'm

How to properly read POST request body in a Handler?

北城以北 提交于 2019-12-01 15:12:52
问题 The code I'm using now: Pooled<ByteBuffer> pooledByteBuffer = exchange.getConnection().getBufferPool().allocate(); ByteBuffer byteBuffer = pooledByteBuffer.getResource(); int limit = byteBuffer.limit(); byteBuffer.clear(); exchange.getRequestChannel().read(byteBuffer); int pos = byteBuffer.position(); byteBuffer.rewind(); byte[] bytes = new byte[pos]; byteBuffer.get(bytes); String requestBody = new String(bytes, Charset.forName("UTF-8") ); byteBuffer.clear(); pooledByteBuffer.free(); It seems

Redirect HTTP to HTTPS in Undertow

谁都会走 提交于 2019-12-01 13:05:41
How can one configure HTTP->HTTPS redirection in Undertow? I've looked through Undertow's codebase, there are some classes that seem to be relevant (e.g. RedirectHandler). Also, Undertow documentation ( Predicates Attributes and Handlers ) seems to target exactly this problem among others. But I'm not sure where to start. Basically, what I'm looking for is some counterpart to Apache's mod_rewrite configuration: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} Thanks! siphiuel This answer pointed in the right direction. Programmatically, one has to

How to Pass Object from ContainerRequestFilter to Resource

对着背影说爱祢 提交于 2019-12-01 05:52:14
问题 How can/should I pass an object from a ContainerRequestFilter to a (post-matching) resource in (JAX-RS) Resteasy version 3.0.11 that has undertow embedded and uses Guice? 回答1: The method ContainerRequestContext#setProperty stores values which are synced with the HttpServletRequest . So with plain JAX-RS you can store an attribute like this: @Provider public class SomeFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws

Wildfly 8.2/undertow read time out

不羁的心 提交于 2019-12-01 05:03:22
问题 I recently migrated my project from jboss4 to wildfly 8.2 with java1.8. I have a webservice call using SAAJ which runs fine in command line. But when its run from within wildfly8.2, it times out after 60 seconds. I read from jboss forums that read requests have a default timeout of 60 seconds. So i changed my configuration in standalone.xml to <ajp-listener name="ajp" socket-binding="ajp" max-parameters="10000"/> **<http-listener name="default" socket-binding="http" max-parameters="10000"

WildFly -> Undertow -> mapping subdomain to war file not working

孤人 提交于 2019-12-01 03:10:29
问题 WildFly 8.1.0 Final Windows Server 2012 R2 I have two sub-domains pointing at this server, and I want requests to each sub-domain to trigger a different war file:- webapp.domain1.com -> WildFly Server -> myapp1.war test.domain2.net -> WildFly Server -> myapp2.war My standalone.xml file is currently configured as follows based on advice received on the JBoss Developer site:- <subsystem xmlns="urn:jboss:domain:undertow:1.1"> <buffer-cache name="default"/> <server name="default-server"> <http

SpringBoot服务器压测对比(jetty、tomcat、undertow)

北战南征 提交于 2019-11-30 03:53:25
(麻烦看这篇的大大们,穿越到这https://my.oschina.net/shyloveliyi/blog/2980868) 1、本次对比基础环境信息如下: springboot版本1.5.10 centos虚机4c6G,版本7.4 centos实机2u16c40G,版本7.4,虚机运行在实机上 ab版本2.3 jprofiler版本9.1.1 2、压测接口说明 天花板:指的是一个空接口,没有任何实现,直接返回,如 @RequestMapping(value = "/test", method = RequestMethod.GET) public void test() { } 服务接口:指的是具有一定业务代码的接口,连接数据库/Redis然后返回json数据 异步接口:指的是开启了http异步 3、压测过程 JETTY 先以Jetty开始,这里通过优化参数来不断摸底。以下是参数说明: jettyMin:最小连接数 jettyMax:最大连接数 mvcCore:线程池core数量 mvcMax:线程池最大量 mvcQueue:线程池队列大小 大致结果如下: JETTY天花板(无异步) jettyMin 50 100 200 300 jettyMax 600 600 600 600 mvcCore 50 50 50 50 mvcMax 200 200 200 200

How can I serve static resources from outside a war on WildFly

感情迁移 提交于 2019-11-29 10:06:07
I may be wrong, but to my understanding, the following must be possible in WildFly: It must be possible to put a link into my JSF views (i. e. the xhtml files) to a resource (pdf, image, other xhtml file) that is already on the WildFly server. I can do the same thing in php and an apache server. Where would I need to put those resources and how can I access them from my views? E. g. put a link in the view to a pdf file that opens the pdf file in a new tab. Thanks a lot for tips and hints!! EDIT standalone.xml <server name="default-server"> <http-listener name="default" socket-binding="http"