Spring5 Webflux Test

Source: Internet
Author: User

Serverresponse Way

@Configuration Public classrouterfunctionconfiguration {@Bean//@Autowired     PublicRouterfunction<serverresponse>Personfindall (userrepository userrepository) {returnRouterfunctions.route (Requestpredicates.get ("/person/find/all"), Request-{Collection<User> users =Userrepository.findall (); Flux<User> Userflux =flux.fromiterable (users); returnServerresponse.ok (). Body (Userflux,user.class);    }); }}

Test

@Test
public void Threadtestorderby () throws Interruptedexception {

Final Long id=141284830240768l;
int threadcount=100000;
Final Countdownlatch begin = new Countdownlatch (1);
Final Countdownlatch end = new Countdownlatch (threadcount);
Final int[] result={0,0};
Final Object lock = new Object ();
Executorservice executorservice = executors.newfixedthreadpool (100);
Long Time1=system.currenttimemillis ();
for (int i = 0; i < ThreadCount; i++) {
Thread thread = new Thread (new Runnable () {
@Override
public void Run () {
try {
Begin.await ();
HTTPPARAMSVO HTTPPARAMSVO = new Httpparamsvo (new Httpsecretvo (Appkey,appsecret), params);
String ResultS = httpclientsecretsendutil.get (URL, HTTPPARAMSVO);
Synchronized (lock) {
result[0]++;
}
} catch (Exception ex) {
Synchronized (lock) {
result[1]++;
}
Ex.printstacktrace ();
}finally{
End.countdown ();
}
}
});
Executorservice.submit (thread);
}
System.out.println (threadcount+ "Start of Thread");
Begin.countdown ();
End.await ();
Long Time2=system.currenttimemillis ();
System.out.println ("Time-consuming:" + (time2-time1)/1000+ "seconds");
System.out.println (threadcount+ "End of Thread Update");
SYSTEM.OUT.PRINTLN ("Success" +result[0]+ ", Failure" +result[1]);
}

Take

servlet mode

@GetMapping ("/person/find/all")    @ResponseBody    public collection<user>  FindAll () {        returnthis. Userrepository.findall ();    }

Test Ibid.

Results

Summarize 100W threads in a case

Spring 5 provides a webflux that is 17 seconds slower than the servlet model

Spring5 Webflux Test

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.