• 【spring cloud】并发测试问题


    一,问题

         并发测试,对外接口测试50个并发的时候开发报错,报错信息类似如下:

     {"status":"0500","message":"GiftExchangeOrderClient#queryExchangeGifts(String,String,String,String) could not be queued for execution and no fallback available.","data":null}
     

    二,方案

    hystrix:
      command:
        default:
          execution:
            timeout:
              enabled: true
            isolation:
              strategy: THREAD
              semaphore:
                maxConcurrentRequests: ${HYSTRIX_COMMAND_MAXCONCURRENTREQUESTS:1000}
              thread:
                timeoutInMilliseconds: ${HYSTRIX_COMMAND_TIMEOUTINMILLISECONDS:30000}
      threadpool:
        default:
          ## 并发执行的最大线程数,默认10
          coreSize: ${HYSTRIX_THREADPOOL_CORESIZE:500}
          ## BlockingQueue的最大队列数
          maxQueueSize: ${HYSTRIX_THREADPOOL_MAXQUEUESIZE:500}
          ## 即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝
          queueSizeRejectionThreshold: ${HYSTRIX_THREADPOOL_QUEUESIZEREJECTIONTHRESHOLD:300}

    三,原理

       1:hystrix的连接线程池限制

    ## 并发执行的最大线程数,默认10
          coreSize: ${HYSTRIX_THREADPOOL_CORESIZE:500}
          ## BlockingQueue的最大队列数
          maxQueueSize: ${HYSTRIX_THREADPOOL_MAXQUEUESIZE:500}
          ## 即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝
          queueSizeRejectionThreshold: ${HYSTRIX_THREADPOOL_QUEUESIZEREJECTIONTHRESHOLD:300}

      2:hystrix的超时设置

         并发大的情况下,响应时间会很长,hystrix的默认超时时间是3秒内,故也会报接口错误问题

       调整

     timeoutInMilliseconds: 30000


    除了hystrix的超时设置之外,还有ribbon超时设置


    四,其他方案
    1: 接口增加缓存
    2: 接口调用优化,重复调用的接口考虑优化

        

    
    
  • 相关阅读:
    门禁控制系统的状态机-《实时控制软件设计》第二周作业
    [leetcode] Single Number
    [leetcode] Candy
    [leetcode] Gas Station
    [leetcode] Clone Graph
    [leetcode] Palindrome Partitioning II
    [leetcode] Palindrome Partitioning
    [leetcode] Surrounded Regions
    [leetcode] Sum Root to Leaf Numbers
    [leetcode] Longest Consecutive Sequence
  • 原文地址:https://www.cnblogs.com/lodor/p/7716244.html
Copyright © 2020-2023  润新知