2014-09-26 3 views
0

비싼 리소스 (예 : 서버의 피클렛 객체)를로드하는 것과 관련된 멋진 패턴을 찾고 있습니다. 여기에 내가 생각해내는 것이있다. 필자는 입력 파일을 파이프 처리하고 느리게 실행중인 프로그램을 bash의 스크립트에 직접 테스트했지만 hadoop 클러스터에서 아직 실행하지 않았습니다. 당신 hadoop 마법사 --- 나는이 파이썬 스트리밍 작업으로 작동합니다 io 처리 오전? 나는 아마존에서 테스트하기 위해 뭔가를 돌릴 것 같지만 누군가 정상을 알고 있으면 좋을 것이다.Hadoop 스트리밍 --- 비싼 공유 리소스 (COOL)

당신이 나에게 잘 보이는 cat file.txt | the_script 또는 ./a_streaming_program | the_script

#!/usr/bin/env python 

import sys 
import time 

def resources_for_many_lines(): 
    # load slow, shared resources here 
    # for example, a shared pickle file 

    # in this example we use a 1 second sleep to simulate 
    # a long data load 
    time.sleep(1) 

    # we will pretend the value zero is the product 
    # of our long slow running import 
    resource = 0 

    return resource 

def score_a_line(line, resources): 
    # put fast code to score a single example line here 
    # in this example we will return the value of resource + 1 
    return resources + 1 

def run(): 
    # here is the code that reads stdin and scores the model over a streaming data set 
    resources = resources_for_many_lines() 
    while 1: 
    # reads a line of input 
    line = sys.stdin.readline() 

    # ends if pipe closes 
    if line == '': 
     break 

    # scores a line 
    print score_a_line(line, resources) 
    # prints right away instead of waiting 
    sys.stdout.flush() 

if __name__ == "__main__": 
    run(); 

답변

0

를 통해 그것을 테스트 할 수 있습니다. 나는 종종 내 매퍼에서 yaml 또는 sqlite 리소스를로드합니다.

일반적으로 이 실행되지 않습니다. 많은 매퍼가 작업에 포함되므로 디스크에서 무언가를로드하는 데 몇 초를 소비하더라도 대개 큰 문제는 아닙니다.