728x90
반응형
728x90
반응형
반응형
  • 인스턴스 여러개 띄운거 -> multi-process
  • 한 인스턴스 안에서 동시 요청 -> multi-thread
    • controller는 스프링에 의해 자동 multi thread(여러 요청이 동시에 들어올 경우)
    • 서비스 로직을 multi-thread로 구현한다는 것은 보통 비동기로 구현하는 것을 의미

 

multi-thread파악

 

11번 우르르쾅쾅 요청하기

curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums & curl -v http://localhost:5000/api/setting/enums

 

서버 설정

스래드 맥스를 5로 잡았다. 

springboot 2.7기준

server.tomcat.threads.max=5
server.tomcat.threads.min-spare=1

10초 딜레이를 넣은 api를 요청했다.

 

결과

5-5-1 순으로 쌓였다가 순차 실행한다.

2023-04-25 07:25:52 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-4] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:25:52 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-2] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:25:52 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-5] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:25:52 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-1] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:25:52 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-3] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

---> 응답 다 받고

2023-04-25 07:26:02 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-2] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:26:02 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-4] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:26:02 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-3] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:26:02 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-5] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

2023-04-25 07:26:02 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-1] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  - 

---> 응답 다 받고

2023-04-25 07:26:12 INFO  [c.n.d.common.filter.RequestLogFilter    .doFilter            :  36][http-nio-5000-exec-1] [REQUEST] [GET] /api/setting/enums
Headers : {host=localhost:5000, user-agent=curl/7.64.1, accept=*/*}
Request body :  -

 

다른 방법:

postman > runner > iteration 을 이용한 run도 응답을 다 받을 때 까지 기다림

https://stackoverflow.com/questions/36157105/postman-how-to-make-multiple-requests-at-the-same-time

 

Postman: How to make multiple requests at the same time

I want to POST data from Postman Google Chrome extension. I want to make 10 requests with different data and it should be at the same time. Is it possible to do such in Postman? If yes, can any...

stackoverflow.com


참고

브라우저로는 테스트가 힘들다..

탭으로 여러개 띄우면 안되고, 브라우저 자체를 여러개 해야하는데 동시 요청이 사실상 힘듦..

정 탭으로 해야하면 url 뒤에 fragment를 다르게 요청하면 된다고 한다.

  • In Chrome, the calls get queued when you call the same resource from two tabs, but executed in parallel when you make the calls from different windows.
  • In IE11, they always get executed in parallel
  • In Firefox, it doesn't matter whether the calls are from different tabs or windows, they always get queued.

All of them execute them in parallel when the URLs are slightly different, by adding a different fragment or parameter.

서버 설정이 1이면 당연히 순차겠지..

https://stackoverflow.com/questions/19774193/subsequent-rest-call-is-blocked-until-previous-one-is-finished

 

Subsequent REST call is blocked until previous one is finished

I Have REST service @Path("/rest") @Component public class MyRestService { @Inject private MyBean bean; @GET @Path("/do") public String start() { this.logger.info("

stackoverflow.com

 

728x90
반응형

+ Recent posts