zuul调优总结

zuul调优

 

设置全局ribbon超时时间

ribbon:

       ConnectTimeout: 60000

       ReadTimeout: 60000

 

通过application-name对应的route-name设置每个服务ribbon超时时间

cloud-demo:

     ribbon:

         ConnectTimeout: 1000

         ReadTimeout: 1000

 

通过default设置hystrix全局超时时间、通过application-name对应的route-name设置服务的hystrix超时时间

hystrix:

  command:

    default:

      execution:

        isolation:

           thread:

              timeoutInMilliseconds: 70000

  cloud-demo:

     execution:

        isolation:

           thread:

              timeoutInMilliseconds: 2000

 

 

设置重试策略

MaxAutoRetriesNextServer: 最多重试几个节点

MaxAutoRetries:每个节点的重试次数(首次调用不包括在内?)

OkToRetryOnAllOperations:对所有的操作进行重试(默认是false)

【建议设置OkToRetryOnAllOperations为false 】

原因在与:post和put操作后台接口没有幂等性可怕

参考博客 https://www.cnblogs.com/zhangjianbin/p/7228628.html

②如果OkToRetryOnAllOperations为false

https://blog.csdn.net/zhxdick/article/details/78906462

 

zuul:

     retryable: true #重试开关

zuul.routes.<routename>.retryable=true 对指定服务关闭开启重试

cloud-demo:

    ribbon:

       MaxAutoRetries: 1

       OkToRetryOnAllOperations: true

        MaxAutoRetriesNextServer: 2

 

ribbon的超时时间要小于hystrix 的超时时间,不然不会触发重试

 

 

设置zuul信号量线程数,针对routename设置

https://www.jianshu.com/p/d401452fe76e

 

 

zuul 调优,待验证

 

tomcat调优

server.tomcat.max-threads=128 # Maximum amount of worker threads. server.tomcat.min-spare-threads=64 # Minimum amount of worker threads.

 

Zuul使用的内置容器默认是Tomcat,可以将其换成undertow,可以显著减少线程的数量,替换方式即在pom中添加以下内容:

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>

 

Zuul默认是使用信号量隔离,并且信号量的大小是100,请求的并发线程超过100就会报错

可以调大该信号量的最大值来提高性能,配置如下:

zuul: semaphore: max-semaphores: 5000

 

也可以改为使用线程隔离,调大hystrix线程池线程大小,该线程池默认10个线程,配置如下:

zuul: ribbonIsolationStrategy: THREAD hystrix: threadpool: default: coreSize: 100 maximumSize: 5000 allowMaximumSizeToDivergeFromCoreSize: true maxQueueSize: -1

 

猜你喜欢

转载自blog.csdn.net/Zzhou1990/article/details/83348456
今日推荐