37

SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

  • Upload
    jay-lee

  • View
    273

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire
Page 2: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

2© 2015 Pivotal Software, Inc. All rights reserved. 2

Apache Geode 와Spring

이창재 ([email protected]) | Pivotal | Advanced Platform ArchitectsApril, 2016

Page 3: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

3© 2015 Pivotal Software, Inc. All rights reserved.

Agenda

� Apache Geode 소개

� Spring Data Gemfire

� Spring Session

� Demo

Page 4: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

4© 2015 Pivotal Software, Inc. All rights reserved.

Page 5: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

5© 2015 Pivotal Software, Inc. All rights reserved.

Page 6: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

6© 2015 Pivotal Software, Inc. All rights reserved.

Apache Geode 는?

open source distributed, in-memory database for scale-out

applications

Page 7: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

7© 2015 Pivotal Software, Inc. All rights reserved.

Geode 는?

� 온라인으로수평확장이가능한고가용성및 Low latency in-memory Data Grid

� Key/Value (Map) Store (+ ααααααααα)

� Open Source– 2015년 4월 Pivotal Gemfire 를Apache 재단에기증– Project Geode– 2016년 4월현재 1.0.0-M2

Page 8: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

8© 2015 Pivotal Software, Inc. All rights reserved.

Geode - In Memory

� Data 를메모리에분산해서저장– JVM Heap– Off Heap 사용가능(defragmentation)

� Disk 에도저장가능– Persistent

� Eviction 과 Expiration 지원– Least Recently Used 기반 Eviction– Time To Live 기반 Expiration

Page 9: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

9© 2015 Pivotal Software, Inc. All rights reserved.

Geode In-Memory 데이타 분산

VM 1

VM 2 VM 3

Page 10: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

10© 2015 Pivotal Software, Inc. All rights reserved.

Server 3Server 2

Bucket 3*primary*

Bucket 1secondary

Bucket 3secondary

Bucket 2*primary*

Server 1

Bucket 2secondary

Bucket 1*primary*

Geode In-Memory 데이타 분산 (Redundant = 1)

Page 11: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

11© 2015 Pivotal Software, Inc. All rights reserved.

Server 3Server 2

Bucket 3*primary*

Bucket 1secondary

Bucket 3secondary

Bucket 2*primary*

Server 1

Bucket 2secondary

Bucket 1*primary*

Geode In-Memory 데이타 분산 (Redundant = 1)

Server 가죽으면?

Page 12: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

12© 2015 Pivotal Software, Inc. All rights reserved.

Server 1 Server 3Server 2

Bucket 2secondary

Bucket 1*primary*

Bucket 3*primary*

Bucket 1*primary*

Bucket 3secondary

Bucket 2*primary*

Bucket 2secondary

Primary Failover

RestoreRedundancy

Bucket 1secondary

Geode In-Memory 데이타 분산 (Redundant = 1)

Page 13: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

13© 2015 Pivotal Software, Inc. All rights reserved.

Geode – PARTITION REGION

� REGION– Database 의 Table– 메모리에분산되서저장되는 java.util.Map

� REDUNDANT 를가지는것과안가지는것(PARTITION, PARTITION_REDUNDANT)– REDUNDANT 즉 Backup 의갯수는지정가능 – 0~3개

� Consistent Hashing– 기본 113 개의 Bucket

� Map API 뿐만아니라 SQL Query 도지원

Page 14: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

14© 2015 Pivotal Software, Inc. All rights reserved.

Geode – Key/Value (Map) Store (+ ααααααααα)

� In Memory Data Grid

� Data Colocation– Master / Detail 형태의 data graph

� Data Serialization (PDX)

� FuctionService

� JTA 호환 Transaction

출처 : http://s.hswstatic.com/gif/grid-computing-1.gif

Page 15: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

15© 2015 Pivotal Software, Inc. All rights reserved.

Geode – Key/Value (Map) Store (+ ααααααααα)

Page 16: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

16© 2015 Pivotal Software, Inc. All rights reserved.

Geode – Key/Value (Map) Store (+ ααααααααα)

Page 17: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

17© 2015 Pivotal Software, Inc. All rights reserved.

Gemfire vs Geode

� Open Source

� 상용 Support

� 기능상의차이– WAN 상의클러스터복제 (M2 에이미포함)– Continuous Query (M2 에이미포함)– C++, C# 지원

Page 18: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

18© 2015 Pivotal Software, Inc. All rights reserved.

Demo Repo

https://github.com/eggboy/springcamp2016geode

https://github.com/eggboy/gemfiredemo

Page 19: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

19© 2015 Pivotal Software, Inc. All rights reserved.

Spring Data Gemfire

Page 20: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

20© 2015 Pivotal Software, Inc. All rights reserved.

Spring Data GemFire (SDG)

Spring Data 의강력하고단순한 프로그래밍모델을이용하여Apache Geode 이용가능.

Spring Ecosystem Integration…– Spring Cache Abstraction / Transaction Management– Spring Data Commons + REST– Spring Integration (Inbound/Outbound Channel Adapters)– Spring Data Flow (Input Source and Sinks)

Page 21: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

21© 2015 Pivotal Software, Inc. All rights reserved.

Apache Geode combined with Spring Data GemFirecan be used as JSR-107 (JCache) caching provider

+ +

Page 22: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

22© 2015 Pivotal Software, Inc. All rights reserved.

GRAILS

Full-stack, Web

Data Flow

Stream, Taps, Jobs

BOOT

Bootable, Minimal, Ops-Ready

Big, Fast,

FlexibleData Web,

Integration,Batch

WEB

Controllers, REST,WebSocket

INTEGRATION

Channels, Adapters,Filters, Transformers

BATCH

Jobs, Steps,Readers, Writers

BIG DATA

Ingestion, Export,Orchestration, Hadoop

DATA

NON-RELATIONALRELATIONAL

CORE

GROOVYFRAMEWORK SECURITY REACTOR

Page 23: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

23© 2015 Pivotal Software, Inc. All rights reserved.

Server 설정

Spring XML 기반설정

Page 24: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

24© 2015 Pivotal Software, Inc. All rights reserved.

Client 설정

Spring XML 기반설정

Page 25: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

25© 2015 Pivotal Software, Inc. All rights reserved.

with Spring

Geode 서버 시작

@SpringBootApplication@ImportResource("/spring-data-gemfire-cache.xml")@EnableGemfireRepositories@EnableTransactionManagementpublic class SampleDataGemFireApplication {

public static void main(String[] args) {SpringApplication.run(SampleDataGemFireApplication.class, args);

}}

혹은…gfsh>start server –name=Example … --spring-xml-location=“spring-data-gemfire-cache.xml”

Page 26: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

26© 2015 Pivotal Software, Inc. All rights reserved.

GemfireRepository

Repository 를 이용한 data 접근

public interface CustomerRepository extends GemfireRepository<Customer, Long> {}

// Spring context.xml<gfe-data:repositories base-package="io.pivotal.springcamp.geode.repository" />

Page 27: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

27© 2015 Pivotal Software, Inc. All rights reserved.

GemfireTemplate

GemfireTemplate 을이용한 data 접근

� 가장단순한 data 접근방법

� Gemfire/Geode API 변경으로부터자유로움

� Exception 이 Spring DAO Exception 으로변경

� Transaction<bean id="customerTemplate" class="org.springframework.data.gemfire.GemfireTemplate" p:region-ref="Customer" />

Page 28: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

28© 2015 Pivotal Software, Inc. All rights reserved.

ImplementationAnnotation-based Function Implementation/Execution

package org.example.app.functions;

import …

@Componentpublic class ExampleFunctions {

@GemfireFunctionpublic Customer update(…) {…

}…

}

Example…

(Optional)…

<bean class=“org.example….ExampleFunctions”/>

Page 29: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

29© 2015 Pivotal Software, Inc. All rights reserved.

ExecutionAnnotation-based Function Implementation/Execution

package org.example.app.function.executions;

import …

@OnRegion(“Example”)public interface ExampleFunctionExecution {

Customer update(…);}

And…<gfe:annotation-driven/>

<gfe-data:function-executions base-package="org.example.app.function.executions">

Page 30: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

30© 2015 Pivotal Software, Inc. All rights reserved.

JSR-107 (JCache), Spring Cache AbstractionGeode Caching Provider

� With @Cacheable� And @CachePut, @CacheEvict(allEntries=[true|false]), @CacheConfig– http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache-jsr-107

� Or with JSR-107 using…– @CacheResult, @CachePut, @CacheRemove, @CacheRemoveAll,

@CacheDefaults

Page 31: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

31© 2015 Pivotal Software, Inc. All rights reserved.

Spring Session 과 Geode

Page 32: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

32© 2015 Pivotal Software, Inc. All rights reserved. 32

12factor App Manifesto - VI. Processes

Twelve-factor processes are stateless and share-nothing.

Some web systems rely on “sticky sessions” – that is, caching user session data in memory of the app’s process and expecting future requests from the same visitor to be routed to the same process. Sticky sessions are a violation of twelve-factor and should never be used or relied upon.

Page 33: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

33© 2015 Pivotal Software, Inc. All rights reserved.

Spring Session

� 일반적인 WAS 의 Clustering– SESSION Replication-> Overhead– 구성의 복잡

� HTTPSession 과 User 의 Object 들이공존– Session 이 차지하는공간으로 인한

Heap 부족

Page 34: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

34© 2015 Pivotal Software, Inc. All rights reserved.

Spring Session

� 플랫폼에독립적인세션관리

� Annotation 기반에쉬운설정

� Persistence

� WebSocket 지원

� 지원하는기술– Redis– Geode– Hazelcast

Page 35: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

35© 2015 Pivotal Software, Inc. All rights reserved.

Spring Session - @EnableGemFireHttpSession

Page 36: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire

36© 2015 Pivotal Software, Inc. All rights reserved.

Spring Session – Servlet Filter

출처 : http://www.slideshare.net/dgomezg/managing-users-data-with-spring-session

Page 37: SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire