Skip to content

@ResponseStatus(HttpStatus.BAD_REQUEST) is 50 times less performant than @ResponseStatus(HttpStatus.UNAUTHORIZED) #35257

@xiaochenxt

Description

@xiaochenxt

version: springboot 3.5.4

@ResponseStatus(HttpStatus.BAD_REQUEST) is 50 times less performant than @ResponseStatus(HttpStatus.UNAUTHORIZED)

Interface hello QPS 1000-2000, interface hello2 QPS 40000-60000

Below is a simple code reproduction:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
</dependency>
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestControllerAdvice
@RestController
@SpringBootApplication
public class Demo1Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);
    }

    @GetMapping("/hello")
    public String hello(){
        throw new ParamsErrorException("error");
    }

    @GetMapping("/hello2")
    public String hello2(){
        throw new Params2ErrorException("error");
    }

    public static class ParamsErrorException extends RuntimeException{
        public ParamsErrorException(String message){
            super(message, null, true, false);
        }
    }

    public static class Params2ErrorException extends RuntimeException{
        public Params2ErrorException(String message){
            super(message, null, true, false);
        }
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler
    public String exceptionHandler(ParamsErrorException e) {
        return "error";
    }

    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    @ExceptionHandler
    public String exceptionHandler(Params2ErrorException e) {
        return "error2";
    }

}
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions