πŸ’»
Albert's Til
GitHub
  • 맀일맀일 μ‘°κΈˆμ”© μ„±μž₯ν•˜κΈ°
    • README
    • CS
      • Network
      • HTTP
        • NO-CACHE
      • 였λ₯˜ μ½”λ“œ
      • ORM 도ꡬ
      • Design Pattern
        • CQRS Pattern
          • Event Sourcing and CQRS pattern
        • Builder Pattern
    • DB
      • MySQL
        • Timeline
        • Pagination
        • Index
        • Database Performance Optimization Strategies
        • B+ tree
        • MySQL Connectors VS MySQL Shell(Scripting) VS MySQL Workbench
        • MySQL Storage Engine Architecture
      • Normalization & Denormalization
      • JPA
        • @Transactional
        • Why JPA?
        • About JPA
        • N+1 Issue
        • Index
        • ElementCollection&CollectionTable
        • orphanRemoval
        • CascadeType
        • Use Subselect
        • Dynamic Instance Creation
        • Paging
        • Order
        • Spefication
        • mappedBy
      • MongoDB
        • ObjectId
      • Why MySQL?
      • ACID properties of transactions
      • Between JPA and JDBC
      • Identifiers in Hibernate/JPA
    • Java
      • Jackson de/serialize
      • Collections.singletonList() vs List.of()
      • Manage dependencies in Gradle
      • Logging Level
      • Bean Validation
      • JVM Internals
        • Threads
          • Frame
        • Shared Between Threads
          • Classloader
            • Class Loader Hierarchy
            • Loading Linking Initialization
      • Java Collection Framework
      • Annotation
      • Generic
      • λ””λ―Έν„° 법칙
    • Spring
      • Caching
      • Spring Integration Overview
        • ThreadPollTaskExecutor
        • Messaging Bridge
        • Channel Adapter
        • Poller
        • Configuration and @EnableIntegration
        • Message Endpoints
        • Message Channels
      • HATEOAS
      • @Autowired vs Constructor Dependency Injection
      • Spring Security
        • JWT 토큰 μ‚¬μš©ν•œ 인가
        • OAuth 2 Login
        • OAuth 2 인증
        • 인가
        • 인증
        • PasswordEncoder
      • IoC Container
      • Filter,Interceptor,AOP,Argument Resolver
      • Spring Annotation
      • About Spring
    • Kafka
      • Error Channel
    • Infra
      • Scale Up || Scale Out
      • Docker
        • Dockerfile
        • Docker Hub Deploy
        • Command
      • Cloud μœ ν˜•
        • Infrastructure as a Service
        • Platform as a Service
        • Software as a Service
      • 무쀑단 배포
        • μ—”μ§„μ—‘μŠ€(Nginx)
      • μ½”λ“œ μžλ™ 배포
        • Technical
      • AWS EC2
        • PEM(Privacy Enhanced Mail) ν‚€
      • AWS RDS
      • AWS S3
    • CodeSquad
      • Spring Boot Project 1μ£Όμ°¨ 회고
      • Spring Boot Project 2μ£Όμ°¨ 회고
      • Spirng Boot Project 3μ£Όμ°¨ 회고
      • Spring Boot Project 4μ£Όμ°¨ 회고
    • Foody Moody ν”„λ‘œμ νŠΈ
      • Query Performance Comparison
      • HeartCount Asynchronous Issue
      • DeferredResult
      • ResponseBodyEmitter
      • SseEmitter (Spring)
      • Server-Sent Events (SSE)
      • 기술 μŠ€νƒ 적용 이유
      • NO-CACHE(HTTP)
      • Transactional
    • DDD
      • AggregateId
    • Test
      • RestAssured
    • Coding and Algorithmic Problems
      • 819. Most Common Word
      • 344. Reverse String
      • 125. Valid Palindrome
      • 937. Reorder Data in Log Files
    • Node
      • Async... Await...
      • Custom Transactional Decorator Challenger
    • Python
      • Python Basic Grammar
        • Comments and Input/Output
        • Variable
        • Data type
        • Operations and syntax
        • List,Tuple,Dictionary,Set
        • Function
        • Conditional statement
        • Loop
    • HTML
      • HTML Basic
      • HTML Basic Tags
      • HTML Form Tags
      • HTML Table Tags
    • CSS
      • CSS Basic
      • CSS Practice
Powered by GitBook
On this page
  • Short Polling ,Long Polling , SSE 비ꡐ
  • Short Polling:
  • Long Polling:
  • Server-Sent Events (SSE):
  • 총결둠:
  • μ‹€μ‹œκ°„ 톡신 방식에 λŒ€ν•œ HTTP/2의 이점
  • HTTP/2의 μ£Όμš” 이점

Was this helpful?

  1. 맀일맀일 μ‘°κΈˆμ”© μ„±μž₯ν•˜κΈ°
  2. Foody Moody ν”„λ‘œμ νŠΈ

Server-Sent Events (SSE)

Short Polling ,Long Polling , SSE 비ꡐ

Short Polling:

  • λ™μž‘ 방식: ν΄λΌμ΄μ–ΈνŠΈκ°€ μΌμ •ν•œ κ°„κ²©μœΌλ‘œ μ„œλ²„μ— μš”μ²­μ„ 보내고 μ„œλ²„λ‘œλΆ€ν„° μ¦‰μ‹œ 응닡을 λ°›μŠ΅λ‹ˆλ‹€. μƒˆλ‘œμš΄ 데이터가 없더라도 응닡은 λ°˜ν™˜λ©λ‹ˆλ‹€.

  • μž₯점: κ΅¬ν˜„μ΄ κ°„λ‹¨ν•˜κ³  λ ˆκ±°μ‹œ μ‹œμŠ€ν…œκ³Όμ˜ ν˜Έν™˜μ„±μ΄ λ›°μ–΄λ‚©λ‹ˆλ‹€.

  • 단점: μƒˆλ‘œμš΄ 데이터가 없을 λ•Œμ—λ„ μš”μ²­κ³Ό 응닡이 μ§€μ†λ˜μ–΄ λΉ„νš¨μœ¨μ μ΄κ³  μ„œλ²„ λ¦¬μ†ŒμŠ€ λ‚­λΉ„κ°€ λ°œμƒν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ˜ˆμ‹œ: (ν΄λΌμ΄μ–ΈνŠΈλŠ” 주기적으둜 μ΄λŸ¬ν•œ μš”μ²­μ„ λ°˜λ³΅ν•©λ‹ˆλ‹€.)

  • ν΄λΌμ΄μ–ΈνŠΈ μš”μ²­:

GET /api/news HTTP/1.1
Host: server.example.com
  • μ„œλ²„ 응닡 (μƒˆ 데이터가 μ—†λŠ” 경우):

HTTP/1.1 200 OK
Content-Type: application/json

{ "data": [] }
  • μ„œλ²„ 응닡 (μƒˆ 데이터가 μžˆλŠ” 경우):

HTTP/1.1 200 OK
Content-Type: application/json

{ "data": [{"title": "New Article", "content": "Content of new article."}] }

Long Polling:

  • λ™μž‘ 방식: ν΄λΌμ΄μ–ΈνŠΈκ°€ μ„œλ²„μ— μš”μ²­μ„ 보내면 μ„œλ²„λŠ” μƒˆλ‘œμš΄ 데이터가 μžˆμ„ λ•ŒκΉŒμ§€ μš”μ²­μ„ 보λ₯˜ν•©λ‹ˆλ‹€. μƒˆ 데이터가 생기면 κ·Έλ•Œ 응닡을 보내고 ν΄λΌμ΄μ–ΈνŠΈλŠ” μ¦‰μ‹œ μƒˆ μš”μ²­μ„ λ³΄λƒ…λ‹ˆλ‹€.

  • μž₯점: μ‹€μ‹œκ°„μ— κ°€κΉŒμš΄ 톡신이 κ°€λŠ₯ν•˜λ©° μƒˆ 데이터가 μ—†μœΌλ©΄ μš”μ²­μ„ 보λ₯˜ν•˜μ—¬ λ¦¬μ†ŒμŠ€λ₯Ό μ ˆμ•½ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

  • 단점: λ™μ‹œ μ—°κ²° μˆ˜κ°€ λ§Žμ•„μ§ˆ 경우 μ„œλ²„μ— 뢀담을 쀄 수 있고, HTTP μ—°κ²° νƒ€μž„μ•„μ›ƒ λ¬Έμ œμ— λŒ€ν•œ μ²˜λ¦¬κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

μ˜ˆμ‹œ:(ν΄λΌμ΄μ–ΈνŠΈλŠ” 응닡을 받은 ν›„ μ¦‰μ‹œ μƒˆλ‘œμš΄ μš”μ²­μ„ λ³΄λƒ…λ‹ˆλ‹€.)

  • ν΄λΌμ΄μ–ΈνŠΈ μš”μ²­:

GET /api/updates HTTP/1.1
Host: server.example.com
  • μ„œλ²„ 응닡 (μƒˆ 데이터가 생길 λ•ŒκΉŒμ§€ λŒ€κΈ° ν›„ 응닡):

HTTP/1.1 200 OK
Content-Type: application/json

{ "data": [{"title": "Updated Article", "content": "Updated content."}] }

Server-Sent Events (SSE):

  • λ™μž‘ 방식: ν΄λΌμ΄μ–ΈνŠΈκ°€ ν•œ 번 μ„œλ²„μ— 연결을 맺으면 μ„œλ²„λŠ” μƒˆλ‘œμš΄ 데이터가 μžˆμ„ λ•Œλ§ˆλ‹€ ν΄λΌμ΄μ–ΈνŠΈλ‘œ 데이터λ₯Ό λ³΄λƒ…λ‹ˆλ‹€. μ΄λŠ” 단방ν–₯ 톡신 채널을 λ§Œλ“­λ‹ˆλ‹€.

  • μž₯점: κ΅¬ν˜„μ΄ 비ꡐ적 κ°„λ‹¨ν•˜λ©°, HTTP ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•˜μ—¬ NAT와 λ°©ν™”λ²½ μΉœν™”μ μž…λ‹ˆλ‹€. λ˜ν•œ μžλ™ μž¬μ—°κ²° κΈ°λŠ₯이 μžˆμŠ΅λ‹ˆλ‹€.

  • 단점: λΈŒλΌμš°μ € ν˜Έν™˜μ„± λ¬Έμ œκ°€ μžˆμ„ 수 있고, λΈŒλΌμš°μ €κ°€ μ•„λ‹Œ ν΄λΌμ΄μ–ΈνŠΈμ—μ„œλŠ” 지원이 μ œν•œμ μΌ 수 μžˆμŠ΅λ‹ˆλ‹€. 이쀑 λ°©ν–₯ 톡신이 ν•„μš”ν•œ 경우 WebSocket을 κ³ λ €ν•΄μ•Ό ν•©λ‹ˆλ‹€.

  • Accept: text/event-stream ν—€λ”λŠ” HTTP μš”μ²­μ—μ„œ μ‚¬μš©λ˜λ©°, μ΄λŠ” ν΄λΌμ΄μ–ΈνŠΈκ°€ μ„œλ²„μ—μ„œ μ „μ†‘λ˜λŠ” 이벀트 μŠ€νŠΈλ¦Όμ„ 받을 μ€€λΉ„κ°€ λ˜μ–΄ μžˆλ‹€λŠ” 것을 λ‚˜νƒ€λƒ…λ‹ˆλ‹€

μ˜ˆμ‹œ:(ν΄λΌμ΄μ–ΈνŠΈλŠ” 연결을 μœ μ§€ν•˜κ³  μ„œλ²„λ‘œλΆ€ν„° 데이터 μŠ€νŠΈλ¦Όμ„ λ°›μŠ΅λ‹ˆλ‹€.)

  • ν΄λΌμ΄μ–ΈνŠΈ μš”μ²­ (μ„œλ²„μ— SSE μ—°κ²° μ΄ˆκΈ°ν™”):

GET /api/events HTTP/1.1
Host: server.example.com
Accept: text/event-stream
  • μ„œλ²„ 응닡 (연결을 μœ μ§€ν•˜κ³  μƒˆ 데이터가 생길 λ•Œλ§ˆλ‹€ λ©”μ‹œμ§€ 전솑):

HTTP/1.1 200 OK
Content-Type: text/event-stream

data: {"title": "Breaking News", "content": "Details about breaking news."}

data: {"title": "Weather Update", "content": "Weather update details."}

총결둠:

  • Short Polling: μ‹¬ν”Œν•œ μƒν™©μ΄λ‚˜ 정기적인 데이터 μ—…λ°μ΄νŠΈκ°€ ν•„μš”ν•˜μ§€ μ•Šμ€ 경우 적합.

  • Long Polling: μ‹€μ‹œκ°„ 데이터λ₯Ό μ²˜λ¦¬ν•΄μ•Ό ν•˜μ§€λ§Œ, SSEλ‚˜ WebSocket 같은 더 λ³΅μž‘ν•œ κΈ°μˆ μ„ μ‚¬μš©ν•˜κΈ° νž˜λ“  경우 적합.

  • SSE: μ‹€μ‹œκ°„μœΌλ‘œ μ„œλ²„μ—μ„œ ν΄λΌμ΄μ–ΈνŠΈλ‘œ 데이터λ₯Ό μ§€μ†μ μœΌλ‘œ ν‘Έμ‹œν•΄μ•Ό ν•˜λŠ” 경우 적합. 이쀑 λ°©ν–₯ 톡신이 ν•„μš”ν•˜μ§€ μ•Šμ„ λ•Œ μ‚¬μš©ν•˜λ©΄ μ’‹μŠ΅λ‹ˆλ‹€.

μ‹€μ‹œκ°„ 톡신 방식에 λŒ€ν•œ HTTP/2의 이점

  • Short Polling:

    • Short Polling은 HTTP/2의 이점을 크게 ν™œμš©ν•˜μ§€ λͺ»ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 닀쀑 μš”μ²­μ„ λ™μ‹œμ— μ²˜λ¦¬ν•  수 μžˆλŠ” λŠ₯λ ₯이 ν–₯μƒλ˜μ§€λ§Œ, μ—¬μ „νžˆ λΉˆλ²ˆν•œ μ—°κ²° μ„€μ •κ³Ό ν•΄μ œλ‘œ μΈν•œ λΉ„νš¨μœ¨μ΄ μ‘΄μž¬ν•©λ‹ˆλ‹€.

  • Long Polling:

    • HTTP/2의 닀쀑화 κΈ°λŠ₯으둜 인해 μ—¬λŸ¬ 개의 Long Polling 연결이 λ™μΌν•œ TCP μ—°κ²° μœ„μ—μ„œ 효율적으둜 μž‘λ™ν•  수 있으며, 헀더 μ••μΆ•μœΌλ‘œ 인해 μ˜€λ²„ν—€λ“œκ°€ κ°μ†Œν•©λ‹ˆλ‹€.

  • Server-Sent Events (SSE):

    • SSEλŠ” HTTP/2와 ν•¨κ»˜ μ‚¬μš©λ  λ•Œ 더 효율적이 λ©λ‹ˆλ‹€. 단일 연결을 톡해 μ—¬λŸ¬ 개의 데이터 μŠ€νŠΈλ¦Όμ„ 전솑할 수 있으며, μ„œλ²„ ν‘Έμ‹œ κΈ°λŠ₯을 톡해 μ—°κ΄€λœ 데이터λ₯Ό ν΄λΌμ΄μ–ΈνŠΈμ— 더 λΉ λ₯΄κ²Œ 전달할 수 μžˆμŠ΅λ‹ˆλ‹€.

HTTP/2의 μ£Όμš” 이점

  1. 닀쀑화(Multiplexing):

    • μ—¬λŸ¬ μš”μ²­κ³Ό 응닡이 λ™μ‹œμ— 같은 연결을 κ³΅μœ ν•  수 μžˆμœΌλ―€λ‘œ μ—¬λŸ¬ 데이터 슀트림이 κ²½μŸν•˜λŠ” λŒ€μ‹  효율적으둜 κ΄€λ¦¬λ©λ‹ˆλ‹€.

    • μ‹€μ‹œκ°„ ν†΅μ‹ μ—μ„œλŠ” ν΄λΌμ΄μ–ΈνŠΈκ°€ μ—¬λŸ¬ 데이터 μŠ€νŠΈλ¦Όμ„ κ°œλ³„μ μœΌλ‘œ λ°›μ•„ μ²˜λ¦¬ν•  수 μžˆμ–΄ νš¨μœ¨μ μž…λ‹ˆλ‹€.

  2. 슀트림 μš°μ„ μˆœμœ„(Stream Prioritization):

    • μš”μ²­μ— μš°μ„ μˆœμœ„λ₯Ό μ§€μ •ν•  수 μžˆμ–΄ μ€‘μš”ν•œ μš”μ²­μ„ λ¨Όμ € μ²˜λ¦¬ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

    • μ‹€μ‹œκ°„ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ—μ„œ μ€‘μš”ν•œ λ©”μ‹œμ§€λ₯Ό μš°μ„ μ μœΌλ‘œ μ²˜λ¦¬ν•  수 μžˆλŠ” 이점이 μžˆμŠ΅λ‹ˆλ‹€.

  3. μ„œλ²„ ν‘Έμ‹œ(Server Push):

    • μ„œλ²„κ°€ ν΄λΌμ΄μ–ΈνŠΈμ˜ μš”μ²­μ„ 기닀리지 μ•Šκ³  예츑 κ°€λŠ₯ν•œ λ¦¬μ†ŒμŠ€λ₯Ό 미리 보낼 수 μžˆμŠ΅λ‹ˆλ‹€.

    • SSE와 같이 μ„œλ²„κ°€ μ΄ˆκΈ°ν™”ν•˜λŠ” 톡신에 μžˆμ–΄μ„œ 더 효율적이 될 수 μžˆμŠ΅λ‹ˆλ‹€.

  4. 헀더 μ••μΆ•(Header Compression):

    • HPACK 압좕을 μ‚¬μš©ν•˜μ—¬ 헀더 데이터λ₯Ό μ••μΆ•ν•¨μœΌλ‘œμ¨ μ˜€λ²„ν—€λ“œλ₯Ό κ°μ†Œμ‹œν‚΅λ‹ˆλ‹€.

    • λͺ¨λ“  μ’…λ₯˜μ˜ μ‹€μ‹œκ°„ ν†΅μ‹ μ—μ„œ λ°˜λ³΅λ˜λŠ” 헀더 μ •λ³΄μ˜ 크기λ₯Ό 쀄여 톡신 νš¨μœ¨μ„ κ°œμ„ ν•©λ‹ˆλ‹€.

  5. λ³΄μ•ˆ κ°•ν™”(TLS Enhancement):

    • HTTP/2λŠ” TLSλ₯Ό μ‚¬μš©ν•˜λŠ” λ³΄μ•ˆ 연결에 μ΅œμ ν™”λ˜μ–΄ 있으며, TLS 1.3κ³Ό ν•¨κ»˜ μ‚¬μš©λ  λ•Œ λ³΄μ•ˆκ³Ό μ„±λŠ₯이 λ”μš± ν–₯μƒλ©λ‹ˆλ‹€.

    • μ‹€μ‹œκ°„ 데이터 μ „μ†‘μ˜ λ³΄μ•ˆμ„ κ°•ν™”ν•˜λ©΄μ„œλ„ μ„±λŠ₯ μ €ν•˜λ₯Ό μ΅œμ†Œν™”ν•©λ‹ˆλ‹€.

Last updated 1 year ago

Was this helpful?