Spring Cloud Netflix Micro-service Stress test

Source: Internet
Author: User
Objective: To carry out stress tests on the set of providers and consumers of micro-service to find out possible problems and ways to solve them.
Create a client project (feign) that provides the HTTP interface to the JMeter call, which uses the feign client to request a micro service on another machine: JMeter--> Client (feign, Hystrix)--> Micro Service (User-service)
Code on the client:
@RestController public
class Usercontroller {
	protected final Logger Logger = Loggerfactory.getlogger (getclass ());
	
	@Autowired
	userserviceclient userserviceclient;

	/**
	 * Get phone number *
	 @param userId * @return Phone number * by User ID *
	 Call Example: http://localhost:12345/ getphonenobyuserid?userid=263508
	/@RequestMapping (value = "/getphonenobyuserid", method = requestmethod.get) Public
	String Getphonenobyuserid (@RequestParam Integer userId) {
		Logger.debug (" Getphonenobyuserid received. userid={} ", userId);
		
		Return Userserviceclient.getphonenobyuserid (userId);
	}

The client invokes the User-service Micro service, and when the test is removed, it is convenient to find the error:
/**
 * Invoke user micro-service Client Interface
 * @author Xujijun
 *
 /
/@FeignClient (value= "User-service", fallback= Userserviceclienthystrix.class)
@FeignClient (value= "User-service") public
interface Userserviceclient {
	/**
	 * According to userid get phone number * * *
	@RequestMapping (value = "/user/getphonenobyuserid", method = requestmethod.get) Public
	String Getphonenobyuserid (@RequestParam (value = "UserId") Integer userId);

Error condition 1 (when thread group is configured with threads of 10, almost must be present): Com.netflix.hystrix.exception.HystrixRuntimeException ... timed-out and no Fallback available. Cause: The default timeout for Hystrix is 1 seconds, and some requests are received for more than 1 seconds due to network problems. Resolution: Configuration Modification Request Timeout (APPLICATION.YML):
Hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutinmilliseconds: 30000 #缺省为1000

error Condition 2 (When thread group configures threads to 1000, it is almost inevitable ):Com.netflix.hystrix.exception.HystrixRuntimeException ... could is queued for execution ... Cause: The Hystix request thread pool defaults to a maximum of 10 threads, and in the case of stress testing, it is easy to explode more than 10 requests. Workaround: Configure modify Coresize (APPLICATION.YML) in the thread pool.
Hystrix:
  threadpool:
    default:
      coresize:500 #缺省为10

After resolving the above two problems, the number of configured threads is 10000, and the failure rate is 0.
Attached: The configuration of this parameter, there is a basic formula can be follow:requests per second to peak when healthyx99th percentile latency in seconds + some breathing Room The maximum number of requests per second (99% average response time + a buffer) For example: 1000 requests per second, 99% of the response time is 60ms, then the formula is: 1000* (0.060+0.012)
Conclusion: 1, the first to maintain the default value of timeout (1000ms), unless you need to modify (in fact, will be modified) 2, the first to maintain threadpool number of threads is 10, unless more than 3, according to the actual business request concurrency number, configure the pressure test concurrent threads number, Then adjust the above two parameters until the demand is met.
Attached: Hystrix Related common configuration information: Timeout time (default 1000ms, Unit: MS) Hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds Number of Hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds thread pool core threads Hystrix.threadpool.default.coreSize (the default is ten) queue hystrix.threadpool.default.maxQueueSize (maximum queue length.) Default-1, using Synchronousqueue. Other values use Linkedblockingqueue. If you want to change from 1 to a different value, you need to restart, that is, the value can not be dynamically adjusted, to dynamically adjust, you need to use the bottom of this configuration. Hystrix.threadpool.default.queueSizeRejectionThreshold (Number of queued threads threshold, defaults to 5, rejected when it is reached, if configured, the queue size is the queue) Note: If maxqueuesize=-1, this option does not work breaker Hystrix.command.default.circuitBreaker.requestVolumeThreshold (when the number of failures in the configuration time window is reached, a short-circuit occurs.) Default 20) Hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds (short-circuit how long after starting to try to recover, default 5s) Hystrix.command.default.circuitBreaker.errorThresholdPercentage (Error percentage threshold, when this threshold is reached, starts short circuit.) Default 50%) fallback Hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests (The calling thread allows the request Hystrixcommand.getfallback () The maximum number, default 10. Exception will be thrown when exceeded, note: This configuration also works for thread isolation mode.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.