In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to configure tomcat and Hystrix in Spring Cloud". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to configure tomcat and Hystrix in Spring Cloud.
1. Replace tomcat
First, replace tomcat with undertow. Under the pressure test of Jmeter, undertow is twice as high as tomcat. The first step is to modify pom to remove tomcat.
Org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat org.springframework.boot spring-boot-starter-undertow
Step 2, configure
Server: undertow: max-http-post-size: thread sets the number of I / O threads, which mainly perform non-blocking tasks. They are responsible for multiple connections. By default, one thread per CPU core is set as the number of CPU cores. Io-threads: blocking task thread pool. When performing a similar servlet request blocking operation, undertow will get threads from this thread pool. Its value setting depends on the load of the system. The following configurations io-threads*8 worker-threads: 3pm will affect buffer. These buffer will be used for IO operations of server connections, which is somewhat similar to netty's pooled memory management # the space size of each buffer, the smaller the space is utilized, the more fully buffer-size: 102 the number of buffer allocated per zone. So the size of pool is buffer-size * buffers-per-region# buffers-per-region: 1024 # this parameter does not need to write # whether to allocate direct memory direct-buffers: true2, replace HTTPClient
The first step is to increase dependence
Io.github.openfeign feign-httpclient
The second part, configure in application.yml or bootstrap.yml
# feign configuration feign: hystrix: # enable hystrix function in feign. By default, feign does not enable hystrix feature enabled: true # # configure httpclient thread pool httpclient: enabled: true okhttp: enabled: false
Step 3, configure HTTPClient Bean
Import java.util.Timer;import java.util.TimerTask;import java.util.concurrent.TimeUnit;import org.apache.http.client.HttpClient;import org.apache.http.client.config.RequestConfig;import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;import org.apache.http.impl.client.HttpClientBuilder;import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration @ Configurationpublic class HttpPool {@ Bean public HttpClient httpClient () {System.out.println ("= Apache httpclient initialization connection pool start ="); / / generate default request configuration RequestConfig.Builder requestConfigBuilder = RequestConfig.custom (); / / timeout requestConfigBuilder.setSocketTimeout (5 * 1000); / / connection time requestConfigBuilder.setConnectTimeout (5 * 1000) RequestConfig defaultRequestConfig = requestConfigBuilder.build (); / / connection pool configuration / / persistent connections for 30 seconds final PoolingHttpClientConnectionManager pollingConnectionManager = new PoolingHttpClientConnectionManager (30, TimeUnit.MILLISECONDS); / / total number of connections pollingConnectionManager.setMaxTotal (1000); / / concurrency of the same route pollingConnectionManager.setDefaultMaxPerRoute (1000); / / httpclient configuration HttpClientBuilder httpClientBuilder = HttpClientBuilder.create () / / to maintain the persistent connection configuration, you need to add Keep-Alive httpClientBuilder.setKeepAliveStrategy (new DefaultConnectionKeepAliveStrategy ()); httpClientBuilder.setConnectionManager (pollingConnectionManager); httpClientBuilder.setDefaultRequestConfig (defaultRequestConfig); HttpClient client = httpClientBuilder.build () in the header; / / start the timer to regularly reclaim expired connections Timer timer = new Timer () Timer.schedule (new TimerTask () {@ Override public void run () {System.out.println ("= closeIdleConnections==="); pollingConnectionManager.closeExpiredConnections (); pollingConnectionManager.closeIdleConnections (5, TimeUnit.SECONDS);}, 10 * 1000, 5 * 1000) System.out.println ("= Apache httpclient initialization connection pool finished ="); return client;}} 3, configure Hystrix
The first step is dependence.
Org.springframework.cloud spring-cloud-starter-hystrix
Step 2, configure
# configure hystrix parameters hystrix: threadpool: # default: default parameter, the role of all hystrix clients, if required for a specific interface You can write the interface + method name default: coreSize: 500command: default: fallback: # whether to enable the fallback method enabled: true execution: isolation: thread: timeoutInMilliseconds: 30000 # default is 1000 Thank you for reading, this is the content of "how to configure tomcat and Hystrix for Spring Cloud", after the study of this article I believe that you have a deeper understanding of how to configure tomcat and Hystrix in Spring Cloud, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.