Upload
dohyun-jung
View
4.261
Download
20
Embed Size (px)
Citation preview
MSA를 이용해 구현하는고가용/고확장성 서비스
자기소개
▪ 정도현– SW컨설턴트/아키텍트
– 일본豆蔵Mamezou
– Blog : moreagile.net
– InfoQ Japan 필진
– QCon2015 준비위원
– SSAG 운영진
Powered by wonderboyfactory.com
Agenda
▪ MSA
▪ DDD
▪ Docker
▪ Spring Boot
▪ Api Gateway
▪ Reactive Microservices Architecture
▪ Conclusion
오늘날의 소프트웨어들의 도전 과제들
▪ 갈수록복잡해지는비즈니스
▪ 짧아지는기술수명주기
▪ 신/구기술이공존하는상황
Google trends - microservices
MSA란?
▪ MobileSuitsMicroServicesArchitecture의약어
▪ 2012년ThoughtWorks의 James Lewis가Java, the Unix way라는제목의발표에서처음으로언급
▪ 2014년 3월 James Lewis와Martin Fowler가Microservices라는타이틀로패러다임을정립한기사를발표– 독립적이고단순한서비스로전체서비스를구성
▪ 데이터, 거버넌스, 아키텍처등에있어서완전한독립
– 독립적인팀이각서비스의개발과운영을담당
▪ 책임과권한에있어서완전한독립을추구
© Sunrise
Service-oriented architecture와 무엇이다른가?
▪ Microservic는 SOA 구분되기위한마케팅적필요에의한선긋기
▪ 동일한목표점
▪ 구현에필요한기술과패러다임이정립되지않았음
▪ 성공과실패의요인을공유– 구현과테스트, 운영등에있어서유용한경험이
SOA의사례를통해축적되어있음.
마이크로서비스의 아홉가지 특징http://martinfowler.com/articles/microservices.html
▪ Componentization via Services / 서비스에의한컴포넌트화
▪ Organized around Business Capabilities / 비즈니스영역에따른조직화
▪ Products not Projects / 프로젝트가아닌프로덕트
▪ Smart endpoints and dumb pipes / 단순한어플리케이션간연동과파이프처리 –유닉스의철학
▪ Decentralized Governance / 개발의분권화
▪ Decentralized Data Management / 데이터관리의분권화 – Polyglot Persistence
▪ Infrastructure Automation / 환경구축의자동화 - DevOps
▪ Design for failure / 장해를전제로한설계
▪ Evolutionary Design / 변화에대응하는설계
Unix way
ps aux | grep conky | grep -v grep | awk '{print $2}' | xargs kill
http://www.slideshare.net/Pivotal/arch-forcd-microservices
Monolithic Architecture의 장/단점
▪ 장점– 심플한구조
– 간편한코드관리
– 간편한트랜젝션관리
– 설계/테스트가간편
▪ 단점– 고장 –다중화
– 개발/운영사이클관리 –브런치/테스트전략
– 확장성 –스케일업
– 신기술도입이어려움
© Sunrise
http://thenewstack.io/the-new-stack-podcast-show-2-the-rise-of-microservices-in-the-paas-world/
조합성
서비스 연결성
느슨한결합
© Sunrise
마이크로서비스 구현 예(도메인구성)
▪ 쇼핑몰사이트– 사용자관리와인증
– 상품등록
– 상품검색
– 카트관리와주문
– 주문처리와배송
– 구입후기관리
▪ 이모든처리가각각별도의도메인으로정의가능
마이크로서비스 구현 예(어플리케이션 구성)
http://www.infoq.com/articles/microservices-intro
마이크로서비스 설계시 고려사항들
▪ 기능적합성
▪ 성능효율성
▪ 호환성
▪ 사용성
▪ 신뢰성
▪ 보안
▪ 유지보수성
▪ 이식성
Agenda
▪ MSA
▪ Docker
▪ Spring Boot
▪ Api Gateway
▪ Reactive Microservices Architecture
▪ Conclusion
도메인 주도 설계Domain-Driven Design
플라톤의 이데아 모델
Powered by wonderboyfactory.com
DDD에서 얻을 수 있는 해법들
▪ 어떤단위로서비스를구성할것인가? – Context Boundary
▪ 서비스의결합 – Aggregate
▪ 변화에강한설계 – Supple Design
▪ 레거시시스템의단계적폐기
▪ 리팩터링전략
Domain Model 정제과정의 예http://agiledata.org/essays/agileDataModeling.html
Agenda
▪ MSA
▪ DDD
▪ Spring Boot
▪ Api Gateway
▪ Reactive Microservices Architecture
▪ Conclusion
마이크로서비스 설계시 고려사항들
▪ 기능적합성
▪ 호환성
▪ 사용성
▪ 보안
▪ 이식성
마이크로서비스의 구성예(Netflix)
http://techblog.netflix.com/2013/01/announcing-ribbon-tying-netflix-mid.html
VMs의 문제점
▪ 가상환경서버라고는해도환경변수나언어버전, 라이브러리버전이달라어플리케이션이동장을하지않는다
▪ 개발환경에서는잘움직이다가도프로덕션환경에서제대로움직이지않는다
▪ 기존환경의가동을중단시키지않으면서도새로운어플리케이션이나기능을추가하는데제약이있음– OS업데이트시에인스턴스 reboot가필요
Docker란?
▪ 구글이 LXC(Linux Containers)호환가상화기술– 컨테이너를구동하기위한플랫폼
▪ 컨테이너란?– 프로그램이작동하기위한최소한의요소들을묶은패키지
▪ Solomon Hykes가 dotCloud사의내부프로젝트로시작
▪ 2013년 3월에오픈소스공개. 2014년 3월 0.9버전릴리즈
▪ Go언어로작성
▪ 다양한통합지원– Google Cloud Platform, Amazon Web Services, Ansible, CFEngine, Chef, Jenkins,
Microsoft Azure, OpenStack Nova,OpenSVC, Puppet, Salt, and Vagrant. (Wikipedia)
벤치마크 결과(기동/종료)http://www.slideshare.net/Flux7Labs/performance-of-docker-vs-vms
벤치마크 결과(I/O)http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf
벤치마크 결과(MySql Throughput)http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf
Docker의 이점
▪ application-centric:어플리케이션중심
▪ portability: 한번의빌드로모든곳에서동일한작동을보장
▪ versioning: Git와닮아있는이미지버전관리기능
▪ automation: 편리한툴을이용한자동화
▪ sharing: Docker Hub를이용해이미지를자유롭게공유– https://hub.docker.com/
▪ reusability: 만들어진이미지는여러가지목적으로재사용가능
Docker hub의 공식 저장소들
Docker맛보기
▪ Boot2Docker설치– https://github.com/boot2docker/windows-installer
▪ 바탕화면에서 Boot2Docker Start를실행
Vagrant를 이용한 Docker이미지 실행
▪ Vagrant란?– VM관리용툴 (VM판maven)
▪ Vagrant를설치– https://www.vagrantup.com/downloads.html
▪ Github에서 docker이미지와 vagrant 설정샘플을다운로드– https://github.com/bubenkoff/vagrant-docker-example
▪ Vagrant명령어로 docker이미지실행> vagrant up
> vagrant ssh
Agenda
▪ MSA
▪ DDD
▪ Docker
▪ Api Gateway
▪ Reactive Microservices Architecture
▪ Conclusion
Spring Boot란?
▪ Spring Framework를이용해어플리케이션을간단하게만들기위한플랫폼
▪ Rails의영향– Spring Roo
– Spring Boot
▪ 모던Java어플리케이션을간단하게구축가능
Spring Boot의 장점
▪ 미리준비된모던자바어플리케이션조합을사용가능
▪ 의존라이브러리를포함시키는것만으로도자동적으로설정이정해짐– Spring, SQL, NoSQL, JMS …
▪ 임베디드톰캣을내장하여간편하게실행이가능– Production Jar 생성기능
▪ 간편하고빠르게작은규모의어플리케이션을빠르게개발/배포하는데특화되어있음
메모리사용량 비교
Install - Maven
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Install - Gradle
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.2.1.RELEASE")
}
Hello
package hello;
import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;
@Controller@EnableAutoConfiguration // 마법의 어노테이션public class SampleController {
@RequestMapping("/")@ResponseBodyString home() {
return "Hello World!";}
public static void main(String[] args) throws Exception {SpringApplication.run(SampleController.class, args);
}}
Run
▪ Maven의경우
> mvn spring-boot:run
▪ Gradle의경우
> Gradle bootRun
▪ Eclipse로부터실행하는경우– Spring Tool Suite (STS) for Eclipse
SpringBoot를 Docker에서 실행하기(Linux)
▪ Sample Download$ git clone http://github.com/adaofeliz/spring-boot-maven-docker.git spring-boot-maven-docker
▪ Build & Run$ cd spring-boot-maven-docker
$ mvn clean install
$ cd target
$ docker build -t spring-boot-maven-docker
pom.xml
<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin><artifactId>maven-resources-plugin</artifactId><executions>
<execution><id>copy-resources</id><phase>validate</phase><goals>
<goal>copy-resources</goal></goals><configuration>
<outputDirectory>${basedir}/target/</outputDirectory><resources>
<resource><directory>.docker</directory><filtering>true</filtering>
</resource></resources>
</configuration></execution>
</executions></plugin>
Dockerfile
FROM dockerfile/java:oracle-java7
ADD spring-boot-maven-docker.jar /opt/spring-boot-maven-docker/
EXPOSE 8080
WORKDIR /opt/spring-boot-maven-docker/
CMD ["java", "-jar", "spring-boot-maven-docker.jar"]
Spring Boot 사용예: Spring Cloud Confighttps://github.com/spring-cloud/spring-cloud-config
Spring Cloud Config 샘플코드
package sample;
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;
@Configuration@ComponentScan@EnableAutoConfigurationpublic class Application {
public static void main(String[] args) {SpringApplication.run(Application.class, args);
}
}
https://github.com/spring-cloud/spring-cloud-config
Agenda
▪ MSA
▪ DDD
▪ Docker
▪ Spring Boot
▪ Reactive Microservices Architecture
▪ Conclusion
API gateway pattern
API gateway pattern
API gateway pattern의 특징
▪ 레거시시스템과의통합
▪ 로드벨런싱
▪ 테스트/ 목업
▪ 고장/예외/로깅공통화
▪ API Aggregation
▪ 검증된다양한제품군
▪ 제약사항파악이중요– 성능, 트랜젝션등
http://microservices.io/patterns/apigateway.html
Agenda
▪ MSA
▪ DDD
▪ Docker
▪ Spring Boot
▪ Api Gateway
▪ Conclusion
Reactive Microservices Architecture란?
▪ Reactive Programming ≒ Functional Programming
▪ Functional Programming– 데이터뿐만이아니라행위도인자값으로전달하는프로그래밍패러다임
▪ 4 Reactive Principles– 1. Event-Driven
– 2. Scalable
– 3. Resilient (Fault Tolerance)
– 4. Responsive
부작용 없는 동시성 프로그래밍
Actor란?
▪ 액터는메시지를수신하고그에대한행위를함께전달하는에이전트이다. 행위의종류에는다음과같은것이있다.
– 메시지를자신또는다른액터에전송한다.
– 액터를생성한다.
– 다음의행동 (replacement behavior)을규정한다.
▪ 액터는메시지를수신하기위해하나의사서함을가진다. 메시지는액터에직접전달되지않고사서함에간접적으로전달된다. 사서함은버퍼링기능이있으나, 메시지는 FIFO로처리되는것은아니다.
▪ 액터가메시지를받으면일단잠금상태가된다. 잠기면메시지는처리되지않는다. 다음액터가 become이되면새로운후계액터가동일한사서함에서메시지를읽고처리를계속한다.
1.기존JAVA의방식
double highestScore = 0.0;
for (Student s : students) {
if (s.gradYear == 2010) {
if (s.score > highestScore) {
highestScore = s.score;
}
}
}
2.Lambda식
double highestScore =
students.filter(#{ Student s -> s.gradYear == 2010 })
.map( #{ Student s -> s.score })
.max();
3.병렬화대응 Lambda식
double highestScore =
students.asParallelStream()
.filter(#{ Student s -> s.gradYear == 2010 })
.map( #{ Student s -> s.score })
.max();
https://medium.com/@andrefaria/migrating-an-application-to-a-reactive-architecture-abf042add86f
MSA를 이용한 대규모 서비스 구현 예
Optimizing the Netflix APIhttp://techblog.netflix.com/2013/01/optimizing-netflix-api.html
▪ dynamic polyglot runtime
▪ fully asynchronous service layer
▪ Reactive programming model
Hystrix
▪ Circuit Breaker패턴을커맨드패턴을이용해구현한라이브러리
▪ Circuit Breaker패턴이란?– 장애가발생한서비스에계속접속할경우, 다른서비스에도장애가전이되는것을막기위해일정시간에러나타임아웃이지정한수치를넘어발생하는서비스에대하여서킷브레이커를발동시켜사용불가상태로전환함
정상상태
미리정해둔수치를넘어타임아웃이나애러가발생할경우접속불
가상태로전환
일정한간격으로서비스상태를체크하여정상으로돌아왔는지를판단
Agenda
▪ MSA
▪ DDD
▪ Docker
▪ Spring Boot
▪ Api Gateway
▪ Reactive Microservices Architecture
Overhead
MSA문제점과 해결책
▪ 설계의어려움– DDD
▪ 레거시시스템과의공존, 인터페이스연계문제– API gateway
▪ 운영오버헤드– DevOps/ NoOps
▪ 코드중복– JVM 또는 .Net상의언어를이용한폴리그랏프로그래밍
▪ 데이터중복
▪ 분산시스템의복잡성과비동기성– Reactive architecure
▪ 테스트의까다로움– API gateway, SOA Testing Techniques
Agile개발과 MSA
▪ 짧은개발주기
▪ 작은개발팀의중요성– 창의적인작업의경우 3-5명으로이루어진팀의효율이가장뛰어남
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.317.7393&rep=rep1&type=pdf
– 인원이많아지면무임승차자가발생
▪ 자율적인팀운영– 아키텍처선정
– 배포주기
프로젝트에서 프로덕트로
Q&A
참고문헌
▪ http://www.slideshare.net/yusuke/jjugccc2014fall-architect
▪ http://www.slideshare.net/makingx/spring-boot-spring-boot
▪ http://projects.spring.io/spring-boot/
▪ http://www.infoq.com/presentations/Micro-Services
▪ http://techblog.netflix.com/2012/12/hystrix-dashboard-and-turbine.htm
▪ http://springinpractice.com/2010/07/06/annotation-based-circuit-breakers-with-spring
▪ http://www.infoq.com/articles/microservices-intro
▪ http://techblog.netflix.com/2013/01/optimizing-netflix-api.html
▪ http://www.slideshare.net/michaelneale/microservices-and-functional-programming
▪ http://www.infoq.com/presentations/Netflix-API-rxjava-hystrix
▪ http://bcho.tistory.com/948
▪ http://www.moreagile.net/2014/10/microservices.html