Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fed02f6
fix: remove implementation logback-classic on gradle (#501)
geoje Sep 5, 2024
7e91356
fix: add threads min-spare configuration on properties (#502)
geoje Sep 5, 2024
4a259b5
test: FileTest 및 IOStreamTest 통과
seunghye218 Sep 4, 2024
fddfdc6
chore: lombok 의존성 추가
seunghye218 Sep 5, 2024
1d08960
feat: 1-1 'GET /index.html 응답하기' 기능 구현
seunghye218 Sep 5, 2024
90931d9
feat: 1-2 CSS 지원하기 기능 구현
seunghye218 Sep 5, 2024
7319283
refactor: getResponse 로직 메서드 분리
seunghye218 Sep 5, 2024
ba5010d
refactor: 간단한 예외처리 추가
seunghye218 Sep 5, 2024
c037870
refactor(HttpRequest): path와 parameters 추가 및 파싱
seunghye218 Sep 5, 2024
7d4f988
feat: 1-3 Query String 파싱 구현
seunghye218 Sep 5, 2024
38a85a1
feat: 2-1 로그인 여부에 따라 페이지 이동 구현
seunghye218 Sep 5, 2024
721b7e9
refactor: HttpResponse 객체 추가
seunghye218 Sep 6, 2024
6f53481
refactor: 메서드 인자 및 이름 변경
seunghye218 Sep 6, 2024
db007a2
fix: 템플릿 엔진 미사용
seunghye218 Sep 6, 2024
36c22be
test: 휴리스틱 캐싱 제거
seunghye218 Sep 6, 2024
add93cd
test: HTTP Compression 설정
seunghye218 Sep 6, 2024
7f37783
fix: 알맞은 resource 이름 반환
seunghye218 Sep 6, 2024
7497b66
test: ETag/If-None-Match 적용
seunghye218 Sep 6, 2024
a633a27
test: 캐시 무효화
seunghye218 Sep 6, 2024
34d44a6
feat: POST 방식으로 회원가입
seunghye218 Sep 6, 2024
837933e
fix: 파라미터 없는 /login 접속 불가능 수정
seunghye218 Sep 6, 2024
1b6cb98
fix: 요청 본문 URLDecode
seunghye218 Sep 6, 2024
0125570
fix: Cookie에 JSESSIONID 값 저장
seunghye218 Sep 6, 2024
4109760
feat: Session 구현
seunghye218 Sep 6, 2024
b3de68a
refactor: 요청 URL 디코딩
seunghye218 Sep 9, 2024
ac157e2
refactor: application/x-www-form-urlencoded MIME 타입 요청 본문 값을 파라미터로 처리
seunghye218 Sep 9, 2024
c3c3791
refactor(HttpResponse): 생성자 추가
seunghye218 Sep 9, 2024
1ceb56d
refactor(HttpResponse): 상태 코드 및 메시지 열거형 분리
seunghye218 Sep 9, 2024
47f234f
refactor: Http11Processor 에서 컨트롤러 로직 분리
seunghye218 Sep 10, 2024
4d930c8
refactor: 정적 자원 캐시 정책 추가
seunghye218 Sep 10, 2024
8162290
refactor: 요청, 응답 헤더 객체화
seunghye218 Sep 11, 2024
351db10
refactor: 로그인 요청 메서드 POST로 변경
seunghye218 Sep 12, 2024
4185398
test: 컨트롤러 및 도매인 테스트 추가
seunghye218 Sep 12, 2024
f733f4a
fix: 키밸류 값 문제 시 패스
seunghye218 Sep 12, 2024
9dd3ef8
chore: 세션 패키지 변경
seunghye218 Sep 12, 2024
759226d
Merge branch 'seunghye218' into seunghye218
seunghye218 Sep 12, 2024
0b20278
refactor: svg 파일 처리 추가
seunghye218 Sep 12, 2024
82f6c1d
refactor: 변수명 변경
seunghye218 Sep 13, 2024
b28e846
chore: 패키지 수정
seunghye218 Sep 13, 2024
66207c9
feat: 스레드 학습 테스트
seunghye218 Sep 13, 2024
f1ed4ab
feat: Executors로 Thread Pool 적용
seunghye218 Sep 13, 2024
208e594
feat: 동시성 컬렉션 사용하기
seunghye218 Sep 13, 2024
0e2df52
Merge branch 'seunghye218' into seunghye218
seunghye218 Sep 13, 2024
f1a1cac
chore: 사용하지 않는 변수 및 import 제거
seunghye218 Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions study/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ handlebars:

server:
tomcat:
accept-count: 1
max-connections: 1
accept-count: 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept-count를 0으로 변경한 이유가 궁금해요 ! 🙋🏻‍♀️

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트에서 명확하게 2개의 요청만 처리하기위해 설정했어요!
tomcat 공식문서를 통해 accept-count 를 listen 함수의 backlog 인자라고 이해를 했어요. 0으로 설정함으로써 이미 max-connections 만큼 연결됐을 때 추가 연결 요청을 무시할 수 있다고 생각했어요.

하지만

The operating system may ignore this setting and use a different size for the queue.
운영 체제는 이 설정을 무시하고 대기열에 다른 크기를 사용할 수 있습니다.

라고 명시되어 있기 때문에 맥 운영체제에서 정확히 어떻게 동작할지는 잘 모르겠네요 😅

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 앞선 2개의 요청이 끝나도 추가 요청이 들어오는 일이 없게끔 하신거군요 ! 👍

max-connections: 2
threads:
min-spare: 2
max: 2
Expand Down
2 changes: 1 addition & 1 deletion study/src/test/java/thread/stage0/SynchronizationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static final class SynchronizedMethods {

private int sum = 0;

public void calculate() {
public synchronized void calculate() {
setSum(getSum() + 1);
}

Expand Down
6 changes: 3 additions & 3 deletions study/src/test/java/thread/stage0/ThreadPoolsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void testNewFixedThreadPool() {
executor.submit(logWithSleep("hello fixed thread pools"));

// 올바른 값으로 바꿔서 테스트를 통과시키자.
final int expectedPoolSize = 0;
final int expectedQueueSize = 0;
final int expectedPoolSize = 2;
final int expectedQueueSize = 1;

assertThat(expectedPoolSize).isEqualTo(executor.getPoolSize());
assertThat(expectedQueueSize).isEqualTo(executor.getQueue().size());
Expand All @@ -46,7 +46,7 @@ void testNewCachedThreadPool() {
executor.submit(logWithSleep("hello cached thread pools"));

// 올바른 값으로 바꿔서 테스트를 통과시키자.
final int expectedPoolSize = 0;
final int expectedPoolSize = 3;
final int expectedQueueSize = 0;

assertThat(expectedPoolSize).isEqualTo(executor.getPoolSize());
Expand Down
2 changes: 2 additions & 0 deletions study/src/test/java/thread/stage2/AppTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package thread.stage2;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stage1의 학습테스트도 LMS에 기재된 것처럼 실패하도록 실행시켜 본 후, 통과하도록 해보는 것도 있으면 좋겠네요 ! 😊

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스레드 강의 끝나고 팀원들과 같이 진행해보았는데 추가 코드를 말씀하신걸까요?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스레드 기준으로 디버거를 돌려도 테스트에 통과할 수 있도록 학습해보면 좋을 것 같다는 의도였어요 ! (커밋 내역에 없어서 여기까지는 안 해보신 줄 알고 😅) 팀원들과 같이 진행해보셨다니! 좋네요 👍


import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.net.http.HttpResponse;
Expand All @@ -21,6 +22,7 @@ class AppTest {
* - http call count
* - 테스트 결과값
*/
@Disabled // 테스트를 실행시키기 위해서 thred.stage2.App을 실행하고 @Disabled를 제거하세요.
@Test
void test() throws Exception {
final var NUMBER_OF_THREAD = 10;
Expand Down
19 changes: 12 additions & 7 deletions tomcat/src/main/java/org/apache/catalina/connector/Connector.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
package org.apache.catalina.connector;

import org.apache.coyote.http11.Http11Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.coyote.http11.Http11Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Connector implements Runnable {

private static final Logger log = LoggerFactory.getLogger(Connector.class);

private static final int DEFAULT_PORT = 8080;
private static final int DEFAULT_ACCEPT_COUNT = 100;
private static final int DEFAULT_MAX_THREADS = 250;

private final ServerSocket serverSocket;
private final ExecutorService executorService;
private boolean stopped;

public Connector() {
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT);
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT, DEFAULT_MAX_THREADS);
}

public Connector(final int port, final int acceptCount) {
public Connector(final int port, final int acceptCount, final int maxThreads) {
this.serverSocket = createServerSocket(port, acceptCount);
this.stopped = false;
this.executorService = Executors.newFixedThreadPool(maxThreads);
}

private ServerSocket createServerSocket(final int port, final int acceptCount) {
Expand Down Expand Up @@ -67,13 +71,14 @@ private void process(final Socket connection) {
return;
}
var processor = new Http11Processor(connection);
new Thread(processor).start();
executorService.submit(processor);
}

public void stop() {
stopped = true;
try {
serverSocket.close();
executorService.shutdown();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.apache.catalina.session;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SessionManager {

private static final SessionManager INSTANCE = new SessionManager();
private static final Map<String, Session> SESSIONS = new HashMap<>();
private static final Map<String, Session> SESSIONS = new ConcurrentHashMap<>();

public static SessionManager getInstance() {
return INSTANCE;
Expand Down