전체 글
-
JVM Memory Leak 만들고 탐지, 개선하기성능테스트 2023. 7. 14. 00:01
개요 memory Leak은 보통 개발자의 실수로 발생할 수 있습니다. 사내에서 Socket과 관련된 코드를 작성하며 Close를 수행하는 절차에서 Memory Leak이 발생시켰던 코드를 예시로 의도적으로 memory Leak을 만들어내고 이를 탐지, 개선하는 작업을 수행해보고자 합니다. Memory Leak이란? 메모리 누수현상이란 프로그램이 필요하지 않은 메모리를 계속 점유하고 있는 현상을 말합니다. Java에서는 GC가 지속적으로 사용하지 않는 객체를 회수하지만 GC에 의해 회수되지 않고 계속 누적되는 현상입니다. 주로 List, HashMap 같은 콜렉션에 해당하는 객체를 해제하지 않고 계속 유지하다 보면 발생하게 됩니다. Memory Leak이 발생하게 되면 어떻게 될까? Memory Lea..
-
FeignClient vs WebClient vs RestTemplateSpring Framework 2023. 7. 13. 00:01
개요 다른 서버와 통신하기 위해서 즉, REST API로 서비스 간 통신하기 위해서 ReignClient, WebClient, RestTemplate 등을 활용하곤 합니다. 이 셋에 대해 알아보고 장/단점에 대해 비교해보고자 합니다. RestTemplate이란? HTTP 요청을 만들기 위해 Spring Framework에서 제공하는 동기식 클라이언트 라이브러리입니다. 오랫동안 인기 있는 선택이였기 때문에 많은 개발자들이 사용법에 익숙하며 대규모 커뮤니티가 존재하는 안정적인 라이브러리입니다. 단점으로는 Blocking I/O를 사용합니다. 이로 인해 동시성이 높은 시나리오에서 성능 문제가 발생할 수 있습니다. 또한 Spring 5.0 이후부터 RestTemplate은 레거시 라이브러리로 간주되면 WebCl..
-
FeignClient 헤더 가져오기Spring Framework 2023. 7. 12. 00:01
개요 FeignClient에서 Header 값 가져오는 방법 Feign @FeignClient( name = "my-feign-client", url = "\${clients.my-server.URL}", ) interface MyFeignClient { @PostMapping(value = ["/test/header"]) fun testFeignGetHeader( @RequestParam("testParam") testParam: String, ): Response 이때 Feign.Response를 통해 가져온다. 호출하는 부분 val response = myFeignClient.testFeignGetHeader(testParam) val token = response.headers()["Authori..
-
Redis replication? Sharding? Sentinel? Cluster?프로젝트/redis 2023. 7. 11. 00:01
개요 Redis를 사용하게 되었을 때 물리 머신이 가진 메모리를 한계를 초과하는 데이터를 저장하고 싶거나, failover(장애)에 대한 처리를 통한 HA(고가용성)을 보장하려면 Sentinel이나 Cluster 등의 운영 방식을 선택해서 사용해야 합니다. 여기서 Sentinel, Cluster, Sharding, Replication 등에 대해 알아보겠습니다. One Redis Instance 가장 단순한 방법입니다. 여러 개의 서버가 단일 Redis 인스턴스를 바라보고 있습니다. 하지만 Redis에 장애가 발생하는 경우 모든 종속 서비스가 중단되는 사태가 발생합니다. 즉, 가용성 또는 내결함성이 없습니다. Redis Replication Redis가 복제(replication)를 통해 HA(High ..
-
캐시 전략CS/데이터베이스 2023. 7. 10. 00:01
캐시 전략이란? 시스템 아키텍처와 Cache Layer를 구성하면서 캐싱전략에 따라 시스템 구성 및 서비스 성능에 영향을 줄 수 있습니다. 이에 따라 상황에 맞는 캐싱 전략을 세우는 것이 좋습니다. 캐시전략을 잘 세우기 위해서는 다음과 같은것들 잘 파악하고 있으면 좋습니다. 어느 종류의 데이터를 캐시에 저장할지 얼만큼 데이터를 캐시에 저장할지 얼마동안 오래된 데이터를 캐시에서 제거할지 자주 조회되는 데이터인지 결괏값은 자주 변동되는지 어떤 전략들이 존재하고 어떨 때 사용하면 좋은지에 대해 알아보고자 합니다. Cache Aside Aside란 ~곁에라는 뜻입니다. 가장 많이 사용하는 전략이며, 캐시를 곁에 두고 필요할 때만 데이터를 캐시에 로드하는 전략입니다. 처음 사용자가 요청하게 되면, 캐시에는 아무런..
-
의미있는 성능테스트성능테스트 2023. 7. 9. 00:01
개요 성능테스트를 진행하면 어떤 환경에서 진행하는 게 의미 있을까? 그리고 각 용어는 어떤 것을 의미하고 어떤 값으로 세팅하는 게 적절할까? 성능테스트의 병목지점은 어떻게 확인할 수 있을까? 1000명의 vUser를 세팅하고, 3000명의 vUser를 세팅하는 등 성능테스트를 진행해 보았지만 몇 명의 vUser가 적절한지 그리고 local환경에서 진행하는 것과 aws 환경에서 진행하는 것의 차이 등에 대해 알아보는 시간을 가지려고 합니다. 성능 테스트 무엇이 목적일까? 서버는 갑자기 사용자가 많아지면 점점 느려지고, 제대로 동작하지 않을 수 있습니다. 성능 테스트를 위해 이를 방지하기 위해 아래와 같은것들을 파악합니다. API의 성능을 측정하고 병목지점이 발생한다면 이를 파악 및 튜닝 CPU 사용률, 메..
-
7장 - 가치 있는 단위 테스트를 위한 리팩터링테스트코드(Test Code)/단위테스트 - 생산성과품질을위한 단위테스트원칙과패턴 2023. 7. 8. 00:01
7장에서 다루는 내용 네 가지 코드 유형 알아보기 험블 객체 패턴 이해 가치 있는 테스트 작성 리팩터링이 필요한 이유 기반 코드를 리팩터링 하지 않고서는 테스트 코드를 크게 개선할 수 없습니다. 코드의 네 가지 유형 도메인 모델 및 알고리즘 : 노력대비 가장 이로운 테스트 지나치게 복잡한 코드 : 한 가지 예로 덩치가 큰 컨트롤러로 모든 작업을 스스로 하는 컨트롤러 컨트롤러 간단한 코드 지나치게 복잡한 코드가 가장 문제가 되며 단위 테스트하기 어렵지만 테스트를 하지 않는 것은 너무 위험합니다. 지나치게 복잡한 코드의 경우 도메인 모델 및 알고리즘, 또는 컨트롤러로 나누어 리팩터링 해야 합니다. 가장 이상적으로는 지나치게 복잡한 코드가 존재하면 안 됩니다. 험블 객체 패턴을 사용해 지나치게 복잡한 코드 분..
-
6장 - 단위 테스트 스타일테스트코드(Test Code)/단위테스트 - 생산성과품질을위한 단위테스트원칙과패턴 2023. 7. 7. 00:01
6장에서 다루는 내용 단위 테스트 스타일 비교 함수형 아키텍처와 육각형 아키텍처의 관계 출력 기반 테스트로 전환 단위 테스트 스타일 3가지 테스트 스타일이 존재합니다. . 출력 기반 테스트 - 가장 품질 좋음 상태 기반 테스트- 두 번째로 좋은 선택 통신 기반 테스트- 간헐적 사용 출력 기반 테스트 테스트 대상 시스템(SUT)에 입력을 넣으면 생성되는 출력을 점검하는 방식입니다. 상품할인을 계산하는 클래스가 존재한다고 가정했을 때 상품을 넣으면 할인된 가격이 나와 해당 가격을 검증할 수 있습니다. 여기서 중요한점은 내부 컬렉션에 상품을 추가하거나, 데이터베이스에 저장하지 않습니다. 이 스타일을 함수형 스타일이라고도 하며 부작용이 없는 함수입니다. 상태 기반 테스트 상태기반은 클라이언트가 상품을 추가했을 ..