Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 试图了解延迟结果性能改进_Spring_Nonblocking_Deferred - Fatal编程技术网

Spring 试图了解延迟结果性能改进

Spring 试图了解延迟结果性能改进,spring,nonblocking,deferred,Spring,Nonblocking,Deferred,我们正试图关注这个博客,了解延迟的结果 在博客中,这个人给出了一个普通的阻塞和非阻塞代码。我把它抄在这里了 该人员运行jmeter并发测试1000个线程5分钟。他提到延迟和tps对于代码的非阻塞是不同的。当我尝试使用具有相同细节的jmeter查看它时,我看到非阻塞和阻塞的延迟都是相同的 我已经尝试过减少和增加次数等 public SpringBootAppController() { timer = new Timer(); ses = new ScheduledThre

我们正试图关注这个博客,了解延迟的结果

在博客中,这个人给出了一个普通的阻塞和非阻塞代码。我把它抄在这里了

该人员运行jmeter并发测试1000个线程5分钟。他提到延迟和tps对于代码的非阻塞是不同的。当我尝试使用具有相同细节的jmeter查看它时,我看到非阻塞和阻塞的延迟都是相同的

我已经尝试过减少和增加次数等

    public SpringBootAppController() {
    timer = new Timer();
    ses = new ScheduledThreadPoolExecutor(10);
}
@RequestMapping("/blockingprocess")
public String blockingProcessing(@RequestParam(value="processingtime") long processingtime) throws InterruptedException
{
    long startTime = System.currentTimeMillis();
    Thread.sleep(processingtime);
    //add more processing later
    long endTime = System.currentTimeMillis();
    long timeTaken = endTime-startTime;
    return  "SUCCESS. Blocking process completed in " + timeTaken + " Ms";
}
@RequestMapping("/nonblockingprocess")
public DeferredResult<String> nonBlockingProcessing(@RequestParam(value="processingtime") long processingtime) throws InterruptedException
{
    DeferredResult<String> deferredResult = new DeferredResult<String>();
    NewProcess j = new NewProcess(deferredResult, processingtime);
    ses.schedule(j,processingtime, TimeUnit.MILLISECONDS);
    System.out.println("hello");
    return deferredResult;
}
publicsspringbootappcontroller(){
定时器=新定时器();
ses=新的ScheduledThreadPoolExecutor(10);
}
@请求映射(“/blockingprocess”)
公共字符串阻塞处理(@RequestParam(value=“processingtime”)long processingtime)抛出InterruptedException
{
long startTime=System.currentTimeMillis();
线程睡眠(处理时间);
//稍后添加更多处理
long-endTime=System.currentTimeMillis();
长时间=结束时间开始时间;
return“成功。阻塞过程在”+时间+“毫秒”内完成”;
}
@请求映射(“/nonblockingprocess”)
public DeferredResult nonBlockingProcessing(@RequestParam(value=“processingtime”)long processingtime)引发中断异常
{
DeferredResult DeferredResult=新的DeferredResult();
NewProcess j=新的NewProcess(延迟结果、处理时间);
ses.时间表(j,处理时间,时间单位毫秒);
System.out.println(“你好”);
返回延迟结果;
}
另一节课

    public NewProcess(DeferredResult<String> deferredresult, long processingtime)
    {
        this.deferredresult = deferredresult;
        this.processingtime = processingtime;
    }

    @Override
    public void run()
    {
        String result = "SUCCESS non blocking process completed in " + processingtime + " Ms";
        deferredresult.setResult(result);
    }
public NewProcess(DeferredResult DeferredResult,长处理时间)
{
this.deferredresult=deferredresult;
this.processingtime=processingtime;
}
@凌驾
公开募捐
{
String result=“成功非阻塞过程在”+processingtime+“Ms”中完成;
延迟结果。设置结果(结果);
}

与阻塞相比,非阻塞的预期性能有所不同。

jmeter中是否有针对非阻塞进程的设置,以确保与deferredresult的异步更快完成?我在本地系统的打印截图上看到了细节。这篇文章质量很差,IMHO。除了
Thread.sleep(processingtime)之外,您打算实际做什么//以后添加更多处理
。因为如果您打算做的是CPU受限的has阻塞IO,那么基于10个线程池计算延迟结果的解决方案将比基于Tomcat更大的请求处理线程池的解决方案差得多。如果您所追求的只是非阻塞、异步IO,那么您可能应该使用WebFlux而不是MVC。