More Related Content Similar to Java 엔터프라이즈 어플리케이션을 효과적으로 마이크로서비스로 전환하기 (박선용, AWS 솔루션즈 아키텍트) :: AWS DevDay2018 (20) More from Amazon Web Services Korea (20) Java 엔터프라이즈 어플리케이션을 효과적으로 마이크로서비스로 전환하기 (박선용, AWS 솔루션즈 아키텍트) :: AWS DevDay20181. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
자바 기업 어플리케이션을 효율적으로
마이크로서비스로 전환하기
Seon Yong, Park
Developer Specialist Solutions Architect
AWS
2. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
발표 순서
마이크로서비스란?
마이크로서비스 전환
도메인 분할
데이터 분할
최선의 플랫폼 선택
어플리케이션 변환
결론
3. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
마이크로서비스란?
4. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
모노리식 vs 마이크로서비스
관리 UI
주문 서비스
인벤토리 서비스
배송 서비스
관리 UI
주문
서비스
인벤토리
서비스
배송
서비스
고객 UI
고객 UI
5. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
마이크로서비스 아키텍처 (장점)
개별 서비스를 소규모 모듈로 구성 가능
장애에 강해 짐
장기적 기술 종속을 감소
CI/CD의 장점을 극대화 함
6. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
마이크로서비스 아키텍처 (단점)
개발 환경의 미성숙 배포의 복잡성 시스템의 메모리
소요가
상대적으로 높아짐
7. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
마이크로서비스 전환
8. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
전환 고려사항
어떤 경우에 마이크로서비스 아키텍처로 전환/검토 해야 하나?
• 쉽고 빠른 어플리케이션의 변경
• 새로운 개발자의 빠른 적응
• 새 기술의 빠른 적용
• CI/CD 의 적용
9. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 서비스와의 매핑
Amazon
S3
Amazon
DynamoDB
AWS Lambda
Amazon API
Gateway
화면 생성 서비스
웹서버
데이터 접근 레이어
앱서비스
데이터베이스
1. 각 요소의
확정 (발견)
• 상태?
• 컴퓨팅?
• API?
• 스토리지?
• 보안?
• 자동관리?
• 확장성?
• 기타
3.
AWS서비스와
매핑
요구에 대한 명세화
(패턴, 분할)
10. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
전환을 위한 실질적 접근
도메인과 데이터를 확인 (도메인 분할)
데이터베이스 마이그레이션(데이터 분리/ 데이터베이서 리팩토링)
마이크로서비스를 위한 최선의 플랫폼 선정
어플리케이션 변경
11. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
도메인 분할 (Domain
Decomposition)
12. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
도메인 분할
비지니스 역량에 기준한 분할
서브 도메인에 의한 분할
동사 혹은 사용케이스에 따른 분할
명사 혹은 리소스에 따른 분할
Ref : https://마이크로서비스.io/patterns/마이크로서비스.html
13. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
기본 가이드 라인의 확인
마이크로서비스 아키텍처 전환시 중요 사항
• 안정적인 아키텍처일 것
• 서비스는 연계가 강한(Cohesive) 기능들의 집합일 것
• 동일한 이유로 변경되는 것들은 하나의 서비스 일 것
• 서비스끼리는 느슨한 결합(loosely coupled)일 것
• 각각의 서비스는 테스트 가능할 것
• 각 서비스는 2 pizza 팀이 개발/관리가 가능할 정도의 규모일 것
가이드 라인
• SRP(Single Responsibility Principle)
• CCP(Common Closure Principle)
14. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
서브 도메인에 의한 구분
도메인 주도 디자인 (DDD : Domain Driven Design)
비지니스의 문제 영역을 도메인으로 호칭
도메인은 여러 개의 서브 도메인으로 구성
서브 도메인 구분
핵심(Core) / 지원(Supporting) / 일반(Generic)
문제점
서브 도메인을 특정하는 것이 어려움
조직적인 문제 : 각기 다른 그룹이 서브도메인과 관련될 수 있음
15. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
분할 전략의 단점
패턴은 매우 추상적이면서 가정에 의존한다
엔지니어는 분할 전략에 대해 충분한 지식이 없는 경우가 많다
Not Practical
Check your database
16. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
분할 전략 실질적 접근
기존 데이터베이스의 데이터를 참고한다
API를 먼저 정의한다. 그에 따라 재구성되는 데이터를 확인한다.
서비스는 독립적인 비지니스 부분(Part)을 담당하는 고유한 존재여야 한다
가능한 데이터 중복이 없도록 서비스를 정의한다
성능, 편의성 등에 의한 데이터 중복을 두려워하지 않는다.
Not Practical
Check your database
17. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
전환을 위한 실질적 접근
도메인과 데이터를 확인 (도메인 분할)
데이터베이스 마이그레이션(데이터 분리/ 데이터베이서
리팩토링)
마이크로서비스를 위한 최선의 플랫폼 선정
어플리케이션 변경
18. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
데이터 분할 (Split Data)
19. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
데이터베이스 전환
메인 데이터베이스
외래키 관계 제거
공유 데이터(Shared Data)
스키마 분리(Schema Splitting)
데이터베이스 리팩토링
리포팅 혹은 분석 데이터
데이터 펌프(Data Pump)
이벤트 데이터 펌프(Event Data Pump)
20. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
외래 키의 제거
유저 제품
유저
서비스
제품
서비스
1:N
사용자 테이블 제품 테이블 사용자 테이블 제품 테이블
모노리식 서비스 마이크로서비스
21. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
공유 데이터
예) country code, zip code, custom code …
금융 제품
사용자 데이터
지불
공유 데이터
금융
서비스
제품
서비스
사용자
서비스
모노리식 서비스 마이크로 서비스
22. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스키마 분리
금융 제품
아이템
지불 금융
서비스
제품
서비스
제품 아이템지불된 아이템
모노리식 서비스 마이크로서비스
23. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
데이터베이스 분리
모노리식
데이터베
이스
금융 제품
금융
금융 제품
제품 금융
금융 제품
제품
하나의
데이터베이스
데이터베이스
분리
어플리케이션
분리
모노리식 서비스 마이크로서비스모노리식 서비스
24. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
분석/리포트 데이터
메인
데이터베
이스
리포트
데이터베
이스
데이타펌프
메인
데이터베
이스
리포트
데이터베
이스
데이타펌프
이벤트
1. 대량의 데이터를 아주 빈번히 HTTP를
통한 전송은 높은 오버헤드가 존재
2. 리포팅 시스템 데이터 동기만을 위한
API는 이득 대비 손실이 너무 큼
데이터 펌프
1. 커플링 이슈 (?)
2. 몇 안되는 예외
이벤트 데이터 펌프
1. 서비스가 이벤트를 발생
2. 이벤트 구독자(데이터펌프)가 데이터를
리포팅 시스템으로 전달
3. 좀 더 디커플링 됨
4. 개발에 많은 부담
25. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
전환을 위한 실질적 접근
도메인과 데이터를 확인 (도메인 분할)
데이터베이스 마이그레이션(데이터 분리/ 데이터베이서 리팩토링)
마이크로서비스를 위한 최선의 플랫폼 선정
어플리케이션 변경
26. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
최선의 플랫폼 선택
27. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
최선의 플랫폼 선택
현재 컨테이너는 마이크로서비스를 위한 최선의 기술
• ECS – 사용이 편이하고 Fargate 선택가능
• EKS – 매니지드 Kubernetes
• 자체 관리 – Kubernetes + Kopss
28. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
관련 AWS Services
Amazon ECSAWS
Lambda
AWS Step
Functions
Amazon API
Gateway
Amazon EKS
AWS Fargate
Amazon ECR
Amazon
S3
Amazon
DynamoDB
Amazon
ElastiCache
Amazon
Aurora
29. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
전환 단계
Amazon ECS
AWS
Lambda
AWS Step
Functions
Amazon API
Gateway
Amazon EKS
AWS Fargate
Amazon
S3
Amazon
DynamoDB
Amazon
Aurora
Amazon
EC2
Amazon
DynamoDB
Amazon
RDS
Amazon
S3
RDS DB
instance standby
(multi-AZ)
RDS DB
instance
read replica
Amazon
EC2
Elastic Load
Balancing
마이크로서비스 (1세대) 마이크로서비스 (2세대)
30. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
전환을 위한 실질적 접근
도메인과 데이터를 확인 (도메인 분할)
데이터베이스 마이그레이션(데이터 분리/ 데이터베이서 리팩토링)
마이크로서비스를 위한 최선의 플랫폼 선정
어플리케이션 변경
31. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
어플리케이션 변환
32. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
어플리케이션 변환 단계
1. HTTP 엔드포인트 생성
2. 설정 정보 외부화
3. 어플리케이션 관련 메트릭과 정보 노출
4. 데이터베이스 변경
5. 도커화와 ECS/EKS를 이용한 배포
6. 클러스터 관리
서비스 발견
장애 관리 :
회로차단 패턴: Kubernetes, Netflix Hystrix, 차단기 클래스 개발
로드 밸런싱
7. 설정, 로깅, 프로파일링, 추적, CI/CD
자바 기업 어플리케이션 변환 단계
33. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
어플리케이션 변환
마이크로서비스 … 분산 시스템 임
다르게 생각할 것 – 어떻게 만들고 배포하고 운영할 것인가
• 단일 프로세스, 공유메모리를 쓰는 모노리식 어플리케이션 개발과I는 다르다.
• 통신 – 상대적으로 신뢰도 낮은 네트워크 vs 공유메모리상의 내부 호출
• 디버깅 – 네트워크 호출로 연결되는 서비스는 추적 및 디버깅이 쉽지 않음
• 에러 핸들링 – API 쓰로틀, 타임 아웃, 하나의 API 실패시 전체 서비스로의 확대
방지 및 호출 제한 고려 필요
• SLA –API공급자가 아키텍처 품질에 대하 기준을 제공하고 준수해야 함(RPS, 평균
응답시간, etc)
• 관리 – 변경관리, 기존 버전에 대한 호환성 및 유지 필요, 안전성 확보
34. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
모노리식 서비스
유저
서비스
이미지
서비스
유저 테이블 이미지 테이블
1:N
포토정보
서비스
포토 테이블
1:N
Application
properties
모노리식 서비스
35. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
0 스텝 : 새 프레임워크를 적용
1 단계 : 현재 패키지, 프레임워크를 진단
2 단계 : 새 프레임워크 선정
3 단계 : 작은 기능 단위를 선택해서 새 프레임워크로 개발
4 단계 : 과거와 신규 개발 코드를 비교
5 단계 : 변환에 필요한 공수를 산정
36. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
<html xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="layout/header"></th:block>
</head>
@Repository
public interface ImageRepository extends JpaRepository<Image, Integer> {
}
0 스텝 : 새 프레임워크를 적용
Maven
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Codes
Spring Boot
Spring Data
Templating
:Thymeleaf
DB Connector
37. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
@Repository
public interface UserRepository extends JpaRepository<User, Integer> {
}
@Controller // This means that this class is a Controller
@RequestMapping(path="/workshop/images")
public class ImageController {
@Controller // This means that this class is a Controller
@RequestMapping(path="/workshop/images")
public class ImageController {
@Component
public class DataLoader implements CommandLineRunner {
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.naming.physical-
strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.h2.console.enabled=true
spring.datasource.driver-class-name=org.h2.Driver
0 스텝 : 새 프레임워크를 적용
Code
Structure
Property file
Interface for
starting
Controller
Model
Repository
Static
Resources
38. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
1 스텝 : HTTP 엔드포인트 생성
@Controller // This means that this class is a Controller
@RequestMapping(path="/workshop/images")
public class ImageController {
@Autowired
private ImageRepository imageRepository;
@GetMapping(path="/add")
public @ResponseBody String addNewUser (@RequestParam String
userid, @RequestParam String bucket , @RequestParam String prefix,
@RequestParam String filename) {
}
Codes
@RestController
@RequestMapping("/workshop/images")
public class ImageController {
@RequestMapping(method = RequestMethod.GET), value=/all)
public @ResponseBody Iterable<Image> getAllUsers() {
@Controller
Controller tell it is a controller, it is simply a specialization of the @Component
class, typically used in combination with a @RequestMapping annotation used
on request handling methods. It requires @ResponseBody
@ RequestMapping
Map specific parts of the HTTP URI path to classes, methods, and parameters in
the Java code.
@ RestController
Map specific parts of the HTTP URI path to classes, methods, and parameters in
the Java code.
@ResponseBody
it will try to convert its return value and write it to the http response automatically.
Annotations
39. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2 스텝 : 설정 정보 외부화
Amazon EC2
Systems
Manager
유저
서비스
이미지
서비스
유저 테이블 이미지 테이블
1:N
포토정보
서비스
포토 테이블
1:N
모노리식 서비스
40. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2 스텝 : 설정 정보 외부화
Maven
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ssm</artifactId>
</dependency>
Code Structure public class CustomConfigListner implements
ApplicationListener<ApplicationEnvironmentPreparedEvent> {
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event)
{
AWSSimpleSystemsManagement client =
AWSSimpleSystemsManagementClientBuilder.standard().build();
GetParameterRequest parameterRequest = new GetParameterRequest();
parameterRequest.withName("datasource.url").setWithDecryption(Boolean.
valueOf(true));
GetParameterResult parameterResult =
client.getParameter(parameterRequest);
String url = parameterResult.getParameter().getValue();
Add a AWS SDK package for
System Manager
Retrieve a
credential & Make a
client instance
org.springframework.context.ApplicationListener=hello.CustomConfigListner A definition for a
custom starter
41. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3 스텝 : 어플리케이션 관련 메트릭과 정보 노출
Amazon EC2
Systems
Manager
모노리식 서비스
API info & MetricsAPI info & Metrics
유저
서비스
이미지
서비스
유저 테이블 이미지 테이블
1:N
포토정보
서비스
포토 테이블
1:N
42. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3 스텝 : 어플리케이션 관련 메트릭과 정보 노출
Maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Mapped "{[/loggers ||
/loggers.json],methods=[GET],produces=[application/vnd.spring-
boot.actuator.v1+json || application/json]}" onto public java.lang.Object
org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.in
voke()
Mapped "{[/beans ||
/beans.json],methods=[GET],produces=[application/vnd.spring-
boot.actuator.v1+json || application/json]}" onto public java.lang.Object
org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.in
voke()
Mapped "{[/auditevents ||
/auditevents.json],methods=[GET],produces=[application/vnd.
Mapped "{[/metrics ||
Console in staring app
/localhost:8080/metrics /localhost:8080/beans
43. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
4 스텝 : 데이터베이스 변경
Amazon EC2
Systems
Manager
API info & MetricsAPI info & Metrics
Amazon
RDS
Amazon
DynamoDB
프로젝트 분리
유저
서비스
이미지
서비스
포토정보
서비스
44. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
4 스텝 : 데이터베이스 변경
Maven
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>4.5.0</version>
</dependency>
Code Structure
@Configuration
@EnableDynamoDBRepositories(basePackages = "hello.repository.ddb")
public class DynamoDBConfig {
@Value("${amazon.aws.accesskey}")
private String amazonAWSAccessKey;
@Value("${amazon.aws.secretkey}")
private String amazonAWSSecretKey;
@Bean
public AmazonDynamoDB amazonDynamoDB() {
AmazonDynamoDB amazonDynamoDB = AmazonDynamoDBClientBuilder.standard()
.build();
return amazonDynamoDB;
}
Add a package of Spring Data for
DynamoDB
Configure the base
dir path for DDB
repository
@EnableScan
public interface PhotoInfoRepository extends CrudRepository<PhotoInfo, String> {
List<PhotoInfo> findAll();
}
Get a credential &
make a instance of
DDB client
45. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
4 스텝 : 데이터베이스 변경
private ImageRepository imageRepository;
Image n = new Image();
n.setUser_id(Integer.parseInt(userid));
n.setBucket(bucket);
n.setPrefix(prefix);
n.setFileName(filename);
imageRepository.save(n);
imageRepository.findAll();
mageRepository.deleteAll();
MySQL
private PhotoInfoRepository phtoInfoRepository;
PhotoInfo n = new PhotoInfo(img_id, locale, img_info);
n.setImg_id(img_id);
n.setLocale(locale);
n.setImgInfo(img_info);
phtoInfoRepository.save(n);
phtoInfoRepository.findAll();
phtoInfoRepository.deleteAll();
DDB
No Differences
46. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
이미지
서비스
5 스텝 : 도커화와 ECS/EKS를 이용한 배포
Amazon EC2
Systems
Manager
API info & MetricsAPI info & Metrics
Amazon
RDS
Amazon
DynamoDB
Amazon
ECR
Amazon ECS
유저
서비스
포토정보
서비스
47. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
5 스텝 : 도커화와 ECS/EKS를 이용한 배포
Docker file
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Docker file to create a docker
image for Java application
docker build -t user-service-img:latest . --build-arg JAR_FILE=”jarfile-0.1.0.jar"
Create a docker image
docker run -p 80:8080
-e AWS_ACCESS_KEY_ID='<access-key>’
-e AWS_SECRET_ACCESS_KEY='<secret-key>’
-e AWS_REGION='<region>’
-it user-service-img bash
Create a local docker image
Run local docker and pass
credential info through
environment variables
docker tag user-service-img:latest
<aws_account_id>.dkr.ecr.<your_region>.amazonaws.com/user-service-repo:latest
docker push <aws_account_id>.dkr.ecr.<your_region>.amazonaws.com/user-service-
repo:latest
Push docker image
Push a local docker image to
ECR repository
48. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (회로차단기 패턴)
회로차단기(Circuit Breaker) 패턴이란?
전기 회로차단기와 같이, 연속된 호출이 존재하는 경우, 하나의 호출이 특정
기준점을 넘는 순간 회로차단기가 실행되고 문제가 되는 API를 호출하는 모든
호출에 대해 에러메시지 혹은 특정 메시지를 리턴하게 하는 패턴
Ref: https://martinfowler.com/bliki/CircuitBreaker.html
49. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (회로차단기 패턴)
코드 구현
1. 회로차단기 객체 생성
2. 회로차단기 인스턴스 생성
3. 회로차단기 인스턴스를 통해서 API를 호출
class CircuitBreaker {
CircuitBreaker(timeout, thredhold, retryTime) {
public call(urlTOcall) {
}
circuitBreaker = new CircuitBreaker(3000, 5, 2000);
response = await circuitBreaker.call(serive B);
Very Complex
50. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (회로차단기 패턴)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
@HystrixCommand
The @HystrixCommand opens the circuit on readingList(), if there is some problems
on member API, then it will return “Adrew Park” only
Add a hystrix package
If no error on member API, You will see, “Seon Yong Park, Andy Jessy, Andrew
Park”
If there is error on member API, You will see, “Andrew Park” only
Maven
Hystrix (Netflix) 사용
@HystrixCommand(fallbackMethod = "reliable")
public String userList() {
URI uri = URI.create("http://localhost:8080/member");
return this.restTemplate.getForObject(uri, String.class);
}
public String reliable() { return ”Andrew Park"; }
Codes
Test
51. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (Istio)
플랫폼 레벨에서 구현: Kubernetes 를 위한 Istio
Istio : 작은 단위의 네트워크 프로토콜 처럼 기능
Refer : https://aws.amazon.com/ko/blogs/opensource/getting-started-istio-eks/
52. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (Linkerd)
Linkerd
• 극히 가벼운 서비스 매쉬
• 레이어 5 프록시
HTTP, Thrift, Mux, HTTP/2, gRPC, etc. (TCP 아님)
요청과 응답을 처리
• Finagle 기반
• 별도의 프로세스로 동작, 라이브러리가 아님.
53. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (Linkerd)
• 로드 밸런싱 지원
• 재시도 à 성공률 향상
• 회로 차단기 à탄력성 향상
• 측정 및 추적 à관찰 가능성
• 전송 보안, 시간 초과, 마감,
• 동적 라우팅, 요청 별 라우팅, ...
• 네트워크 통신이 복잡해짐
• 위와 같은 기능을 새로 개발할 필요 없음.
• 라이브러리는 특정 언어 종속적
54. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (로깅)
3
3
3
3
3
3
55. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (로깅)
ECS 로그 드라이버
Awslogs
Fluentd
Gelf
Journald
…
56. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (로깅)
ElasticSearch로 로그스트림
생성
ElasticSearch
Query
curl -XPOST -H 'Content-Type: application/json' 'https://fdffdsafds/cwl-2018.08.14/_search' -
d'
{
"size": 0,
"aggs": {
"average_diff": {
"avg": {
"field": "diff"
}
},
Result
{"took":8,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"tot
al":7863,"max_score":0.0,"hits":[]},"aggregations":{"count_diff":{"value":6000},"average_diff":{
"value":2028.9538333333333},"max_diff":{"value":4447.0},"min_diff":{"value":14.0}}}
57. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
스텝 6 : 클러스터 관리 (프로파일링)
Deep Code Analysis
• JProfiler
• YourKit
• Java VisualVM
Spring AOP(Aspect Oriented Programming)
@Configuration
@EnableAspectJAutoProxy
@Aspect
public class AopConfiguration {
}
AopConfiguration
PerformanceMonitorInterceptor
public class PerformanceMonitorInterceptor extends AbstractMonitoringInterceptor {
@Pointcut("execution(public int com.aws.sample.PersonService.getAge(..))")
public void myMonitor() { }
public PerformanceMonitorInterceptor() {
}
58. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
결론
59. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Conclusion
• 시스템 설계단계 부터 마이크로 서비스 아키텍처를 고려
• 기존 어플리케이션에 대한 전환 계획 수립
• 도메인 발견, 분할, 데이터베이스 전환, 어플리케이션 변환 등에 대한
단계적이고 실질적 접근을 고려할 것
• 데이터 분할에 대한 전략을 고려
• 컨테이너 기술과 서버리스 서비스 등 최신 기술을 적극 활용할 것
• 표준 AWS 서비스를 활용
• 써드파티 솔루션 활용을 고려할 것
• 자바 환경에 맞는 프레임워크, 프로그래밍 솔루션을 고려할 것
• 지속적인 개선을 통해 진화시킬 것
60. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• 세션 후, 설문에 참여해 주시면 행사 후 소정의 선물을 드립니다.
• #AWSDevDay 해시 태그로 의견을 남겨주세요!