spark 1.6을 기준으로 spark sql에 대해서 개략적으로 설명한 자료입니다. 발표 자료가 친절하지 않으나 한글로 된 자료가 없길래 혹시나 도움 되시는 분들이 있을까 하여 공유합니다.
발표자료 보다는 마지막 페이지의 참고자료들을 읽어보시기를 권장 드립니다.
출처만 남겨주시면 자유롭게 가져가셔서 사용하셔도 무방합니다.
1일 수천대의 서버에서 발생하는 30~50억건의 Log와 Metric을 처리하는 Planet Mon 을 지탱하는 기술인 Collection(Collectd, NXlog), Transport(Kakfa, Logstash), Log Stream Analytics, Storage(Elasticsearch), Visualization을 구성하는 Architecture에 대해 설명드리고 제가 개발한 Log Stream Analytics 서버들의 구현 기술에 대해 좀더 상세히 설명합니다.
spark 1.6을 기준으로 spark sql에 대해서 개략적으로 설명한 자료입니다. 발표 자료가 친절하지 않으나 한글로 된 자료가 없길래 혹시나 도움 되시는 분들이 있을까 하여 공유합니다.
발표자료 보다는 마지막 페이지의 참고자료들을 읽어보시기를 권장 드립니다.
출처만 남겨주시면 자유롭게 가져가셔서 사용하셔도 무방합니다.
1일 수천대의 서버에서 발생하는 30~50억건의 Log와 Metric을 처리하는 Planet Mon 을 지탱하는 기술인 Collection(Collectd, NXlog), Transport(Kakfa, Logstash), Log Stream Analytics, Storage(Elasticsearch), Visualization을 구성하는 Architecture에 대해 설명드리고 제가 개발한 Log Stream Analytics 서버들의 구현 기술에 대해 좀더 상세히 설명합니다.
I will make this presentation for seminar of NIPA
For more information of the seminar, please go to http://www.software.kr/user/seminar.mbs?id=swkr_050102000000&command=view&idx=376830
MEAN 스택을 사용한 IoT 개발 예제를 설명합니다.
* MEAN 스택 기본 내용 소개
* Node.js와 Express를 활용한 간단한 CRUD 서버 작성 방법(아주 단순하지만 (인증을 제외한 나머지) RESTful 서버의 기본 내용을 구현함)
* MongoDB와 Mongoose ODM를 사용한 영속적인 자료 저장 방법
* AngularJS를 사용한 아주 간단한 모니터링 도구 구현(하지만 의존성 주입, 양방향 자료 결합, 라우팅 활용 방법이 모두 들어 있음)
* 모든 예제는 bitbucket(git 호스팅 서비스)에 공개되어 있음
Create-React-App으로 SSR을 구현하며 배운 점 (feat. TypeScript)LanarkSeung
프로덕션 환경에서 클라이언트 사이드 렌더링을 고집하기란 힘든 일입니다. 서버를 통해 웹사이트를 제공하면서도 React의 편리함을 누리려면 서버 사이드 렌더링(SSR)을 구현해야 하는데요. Create-React-App을 그대로 유지하면서 SSR을 구현하는 과정을 보여드리고자 합니다. TypeScript로도 가능합니다!
빅데이터 기술의 소프트웨어 공학 적용
1. 빅데이터 기술의 활용 사례 - 빅데이터 기술은 이미 많은 적용 사례를 가지고 있고, IoT 기술과 더불어 일상의 기술이 되어 가고 있다 (Pervasive & Invisible Analytics).
2. Spark 플랫폼 - 이전에 Hadoop으로 대표되는 빅데이터의 분산 처리 기술은 계속 발전하고 있고, Spark는 메모리 기반 데이터 처리로 기존 대비 성능을 10~100배 개선하였다. 특히, Spark는 Scala라는 함수형 언어로 구현되었고, 이전에 Java 기반의 빅데이터 처리 코드를 보다 명료하고 Compact하게 구현할 수 있다. 데이터 분석에는 Imperative 언어보다 함수형 언어가 보다 적합하다.
3. 소프트웨어 공학에서의 데이터 분석 사례 - 최근 Software Analytics, Repository Mining 등 데이터 분석 사례들이 있고, 최근 GitHub 이나 StackOverflow 분석과 같은 빅데이터 분석 연구들이 진행되고 있다.
4. Spark를 활용한 Word Count 예
5. Big Data Software Engineering - 큰 데이터 처리 외에도, 실시간 데이터 처리 (Velocity), 다양한 데이터 처리 (Variety) 부분에도 소프트웨어 공학 적용이 필요하다. 또한, Big Data Software를 Engineering하는 부분에도 관심이 필요하다. Big Data 분석 코드 역시 SE의 대상으로 바라보고, Test Driven Dev, Agile Methodology와 같은 개발 방법의 적용을 살펴볼 필요가 있다.
마지막으로, 현재 빅데이터 기술에 대한 진입 장벽은 많이 낮아졌고, 사용 가능한 오픈소스들이 많다. 소프트웨어 공학자라면 빅데이터 분석을 직접 시도해 볼 필요가 있고, 특히, Spark-Scala는 향 후 더욱 발전 확대될 기술이다.
2. Lambda Architecture
Lambda Architecture는 Nathan Marz 에 의해 대중화된용어로 scalable and fault-tolerant data processing
architecture.
Backtype과 Twitter에서 분산 데이터 처리 시스템에서일한 경험이 바탕이 됨.
3. Lambda Architecture 1. All data entering the system is dispatched to both the
batch layer and the speed layer for processing.
2. The batch layer has two functions: (i) managing the
master dataset (an immutable, append-only set of
raw data), and (ii) to pre-compute the batch views.
3. The serving layer indexes the batch views so that
they can be queried in low-latency, ad-hoc way.
4. The speed layer compensates for the high latency of
updates to the serving layer and deals with recent
data only.
5. Any incoming query can be answered by merging
results from batch views and real-time views.
출처 : http://lambda-architecture.net/
4. Batch layer and Speed layer
ALL Data
New data
stream
(Kafka)
Storm
Hadoop MR
Cassandra
Hbase
Riak
ElephantDB
Voldemort
Query
5. Hadoop MapReduce
● Mapper :
○ Processes input key/value pair,
○ Produces set of intermediate
pairs.
● Reducer :
○ Combines all intermediate
values for a particular key,
○ Produces a set of merged
output values
7. Mapper
public static class Map extends Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
String line = value.toString(); // <label id="code.map.tostring"/>
Iterable<String> words = new Words(line); // <label id="code.map.words"/>
for (String word: words)
context.write(new Text(word), one); // <label id="code.map.write"/>
}
}
8. Reducer
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val: values)
sum += val.get();
context.write(key, new IntWritable(sum));
}
}
9. Driver
public class WordCount extends Configured implements Tool {
public int run(String[] args) throws Exception {
Configuration conf = getConf();
Job job = Job.getInstance(conf, "wordcount");
job.setJarByClass(WordCount.class);
job.setMapperClass(Map.class); // <label id="code.mapperclass"/>
job.setReducerClass(Reduce.class); // <label id="code.reducerclass"/>
job.setOutputKeyClass(Text.class); // <label id="code.keyclass"/>
job.setOutputValueClass(IntWritable.class); // <label id="code.valueclass"/>
FileInputFormat.addInputPath(job, new Path(args[0])); // <label id="code.inputpath"/>
FileOutputFormat.setOutputPath(job, new Path(args[1])); // <label id="code.outputpath"/>
boolean success = job.waitForCompletion(true); // <label id="code.waitforcompletion"/>
return success ? 0 : 1;
}
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new WordCount(), args);
System.exit(res);
10. 지역적으로 실행하기
$ hadoop jar target/wordcount-1.0-jar-with-dependencies. jar input output
16. XML 처리하기-Mapper
public static class Map extends Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private final static Pattern textPattern =
Pattern.compile("^<text.*>(.*)</text>$", Pattern.DOTALL);
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
String text = value.toString();
Matcher matcher = textPattern.matcher(text);
if (matcher.find()) {
Iterable<String> words = new Words(matcher.group(1));
for (String word: words)
context.write(new Text(word), one);
}
}
}
17. 하둡을 사용하는 것이 전적으로 속도
때문인가?
대용량 분산 처리
장애를 처리하고 회복할수 있음
● 노드 장애 : 장애가 발생한 노드에서재시도(map, reduce 재 실행)
● 디스크 장애 : 데이터를여러 노드에 중복하여저장하는장애 허용 분산 파일 시스템
● 유한한 메모리 : 메모리에전체 데이터를모두 올리는 대신, 처리하는동안 HDFS에 키/값쌍 들을 저장
18. 1일차 마무리
● Hadoop streaming API : https://hadoop.apache.org/docs/r1.2.1/streaming.html
● Hadoop pipe API : https://hadoop.apache.org/docs/r1.2.1/api/org/apache/hadoop/mapred/pipes/package-summary.html
● Hadoop java/scala api
○ Scalding : http://www.cascading.org/projects/scalding/
○ Cascading : http://www.cascading.org/projects/cascading/
○ Cascalog : http://cascalog.org/
19. 전통적인 데이터 시스템의 문제
● 규모 - 복제, 샤딩으로 확장... 장비가 늘어날수록 질의가 많이 질수록 쉽지 않다!
● 유지보수 오버 헤드 - 여러대의 컴퓨터에 퍼져있는 데이터 베이스관리 쉽지 않다!
● 복잡성 - 복제와 샤딩은 어플리케이션의 지원이 필요
● 사람의 실수 - 사람이 저지르는 잘못을 처리하는 것
● 과거의 정보에 대한 접근이 필요한 분석과 보고서
20. Batch layer
● 불멸의 진리 데이터 : 원천 데이터 + 도출된 데이터
● 원천데이터가 불변이 될려면 ?
○ 타임스탬프 만 추가하면 된다.
● 원천데이터가 불변이면 ...
○ 대량의 데이터를 처리할 수 있는 고도의 병렬성
○ 만기도 쉽고 장애도 잘 일어나지 않는 단순함
○ 기술적 고장이나 사람의 실수를 허용하는 능력
○ 매일의 업무는 물론 과거의 데이터를 대상으로 하는 보고서나 분석도 가능하게 만드는
능력
● "지연"이라는 단점이 있음
26. Service Layer 배치뷰 업데이트에적합한 서비스 계층 DB ?
ElephantDB (Clojure)► This is system created exactly for
this case. It is very simple.
참조: http://www.slideshare.net/nathanmarz/elephantdb
Voldemort(java) ► NoSQL, Pluggable Storage engines,
Consistent hashing, Eventual consistency, Support for
batch-computed read-only stores
An open source clone of Amazon's Dynamo.
출처 :
http://www.slideshare.net/DavidGroozman/challenge-26788828
27. Speed Layer ● Batch Layer 속도 지연의 극복
● 점진적인 접근 방식을 사용
● 무작위 쓰기를 허용하는
전통적인 데이터베이스를
사용
35. Record Bolt
class ContributionRecord extends BaseBasicBolt {
private static final HashMap<Integer, HashSet<Long>> timestamps = // <label id="code.recordertimestamps"/>
new HashMap<Integer, HashSet<Long>>();
public void declareOutputFields(OutputFieldsDeclarer declarer) { // <label id="code.recorderdeclare"/>
}
public void execute(Tuple tuple, BasicOutputCollector collector) { // <label id="code.recorderexecute"/>
addTimestamp(tuple.getInteger(2), tuple.getLong(0));
}
private void addTimestamp(int contributorId, long timestamp) { // <label id="code.addtimestamp"/>
HashSet<Long> contributorTimestamps = timestamps.get(contributorId);
if (contributorTimestamps == null) {
contributorTimestamps = new HashSet<Long>();
timestamps.put(contributorId, contributorTimestamps);
}
contributorTimestamps.add(timestamp);
}
}
36. Topology
public class WikiContributorsTopology {
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder(); // <label id="code.topologybuilder"/>
builder.setSpout("contribution_spout", new RandomContributorSpout(), 4); // <label id="code.setspout"/>
builder.setBolt("contribution_parser", new ContributionParser(), 4). // <label id="code.shufflegrouping"/>
shuffleGrouping("contribution_spout");
builder.setBolt("contribution_recorder", new ContributionRecord(), 4). // <label id="code.fieldsgrouping"/>
fieldsGrouping("contribution_parser", new Fields("contributorId"));
LocalCluster cluster = new LocalCluster();
Config conf = new Config();
cluster.submitTopology("wiki-contributors", conf, builder.createTopology()); // <label id="code.submittopology"/>
Thread.sleep(10000);
cluster.shutdown(); // <label id="code.clustershutdown"/>
}
}
37. Stream Group
스톰의 스트림 그룹은 어느 작업자(Task)가 어느 튜플을 받는가라는 질문에 대한 대답을 제공한다.
(http://storm.apache.org/releases/current/Concepts.html)
Shuffle grouping
튜플이 볼트의 작업자(Task)에 랜덤하게 분산됨.
Fields grouping
튜플이 가지는 특정 데이터 필드에 따라 작업자(Task)가 선택됨. 예를들어 만약 튜플이
contributorId로 그룹되어 진다면, 동일한 contributorId를 가지는 튜플들은 항상 동일한 작업자(Task)에
가게 됨.
Global grouping
전체 튜플은 볼트의 작업자(Task)중 하나로만 가게됨. (가장 낮은 아이디의 작업자로 가게됨)
38. Stream Group
All grouping
하나의 튜플이 모든 볼트 작업자 들에 전달됨. (모든 볼트 작업자 들에 브로드캐스트 됨)
Direct grouping
튜플의 생산자는 어떤 작업자가 이 튜플을 받을 것인지를 결정함.(1:1)
Local or shuffle grouping
Target 볼트가 동일한 작업자(Task) 프로세스에 하나 이상의 작업을 수행할 경우, 튜플 작업을
in-process 작업으로 처리함. 그렇지 않으면 일반적인 Shuffle grouping과 같이 동작
Partial Key grouping
Fields grouping과 같이 튜플이 가지는 특정 데이터 필드에 따라 작업자가 선택되지만, 두개의
downstream 볼트 사이에 부하가 배분됨.
39. 3일차 마무리
속도 계층은 최근 데이터에 대한 실시간 뷰를 제공
속도 계층의 스톰은 비동기적인 속도 계층을 만들 때 사용
40. 마치며
● 람다 아키텍처 - 여러 개념을 하나로 통합
○ 원천 데이터 불변 : 클로저가 아이덴티티와 상태를 분리하는것을 연상
○ Mapper/Reducer 병렬처리 : 병렬적 함수 프로그래밍과 유사
○ 작업과정을 클러스터에 분산 : 액터
○ 스톰 튜플의 스트림 : 액터와 CSP 메시지 전달
● 장점/단점
○ 람다 아키텍처는 거대한 양의 데이터를 다루기 위한 것/거대한 양의 데이터 - > 오버헤드
● 대안
○ 스파크는 DAG 실행 엔진을 구현하는 수많은 알고리즘(특히 그래프 알고리즘)이
맵리듀스와 비교해서 더 자연스럽게 표현되도록 만들어주는 클러스터 컴퓨팅 프레임워크
■ 내부에 스트리밍 API : 배치 계층과 속도 계층이 모두 구현 가능