2011년 6월 26일 일요일

node.js 설치

리눅스,맥은 아래와 같이 하면 됨

설치전에 해야 할것
sudo apt-get install libssl-dev
sudo apt-get install g++
git clone --depth 1 https://github.com/joyent/node.git
cd node
git checkout origin/v0.4 # optional. Note that master is unstable.
export JOBS=2 # optional, sets number of parallel commands.
mkdir ~/local
./configure --prefix=$HOME/local/node
make
make install
echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.profile
source ~/.profile
npm 설치


curl http://npmjs.org/install.sh | sh
npm 모듈 설치

전체 lib 로 설치시
npm install 설치모듈 -g
=> 설치위치는 $NODE_JS_HOME/npm_module/설치모듈

npm install 설치모듈
=> 현재위치 아래 설치됨

우분투 11.04 기준
sudo apt-get install node 하면 안됨.

위와 같이하면 npm 설치 안됨

2011년 6월 10일 금요일

thrift

소개

  • thrift는 페이스북에서 scalable backend service 와 효율적인 구현을 하기 위한 라이브러리이면서 코드 generating tool 이다
  • 각 언어에서 추상적인 portion에 의한 programing language로 효율적이고 신뢰할 수 있는 communication에 목적이 있다.
  • thrift는 개발자가 자체 언어를 쓴 파일에서 datetype과 service를 정의할 수 있도록 해준다.
  • RPC client, server를 빌드하기 위한 code generating을 할 수 있다.

구조

Transport

  • 생성된 코드로 데이터 전송을 쉽게 해주는 layer
  • 생성된 코드와 Transport layer와 decouple 하게 하는게 key design
  • 어떤 언어에서는 사용가능한 심플한 구조를 가짐
  • 소켓위에서 최소한의 명령어만 가짐.(write ...)
  • 그외에 listen, accept 만 있음
TSocket
  • 모든 target 언어를 통해서 구현되어 있고, 공통적으로 사용하는 TCP/IP stream socket를 제공함
TFileTransport
  • The TFileTransport is an abstraction of an on-disk file to a data stream.
  • It can be used to write out a set of incoming Thrift requests to a file on disk
Protocol
  • A second major abstraction in Thrift is the separation of data structure from transport representation
  • XML, ACSII, binary 상관없이 자동생성된 코드에 의해 읽고 쓰기가 가능하다.

Versioning

  • thrift는 versioning과 데이터 정의 변화에 대해 강력하다.
  • case
    • Added field, old client, new server. In this case, the old client does not send the new field. The new server recognizes that the field is not set, and implements default behavior for out-of-date requests.
    • Removed field, old client, new server. In this case, the old client sends the removed field. The new server simply ignores it.
    • Added field, new client, old server. The new client sends a field that the old server does not recognize. The old server simply ignores it and processes as normal.
    • Removed field, new client, old server. This is the most danger- ous case, as the old server is unlikely to have suitable default behavior implemented for the missing field. It is recommended that in this situation the new server be rolled out prior to the new clients.

RPC Implementation

TProcessor
  • The key design idea here is that the complex systems we build can fundamentally be broken down into agents or services that operate on inputs and outputs.
  • 핵심 디자인 아이디어는 여기에 우리가 건설 복잡한 시스템은 기본적으로 대리인이나 서비스 입력 및 출력 작업으로 분류 될 수있다는 점입니다.(구글번역)
TServer
  • The server encapsulates the logic around connection handling, threading, etc. while the processor deals with RPC.
  • single-threaded TSimpleServer, thread-per-connection TThreadedServer, and thread-pooling TThreadPoolServer

참조

type

  • 개발자가 이용할때 programming language에서 아무런 문제가 생기지 않고 개발하는 언어에 완벽히 대응하는 type를 제공하는 걸 목표로 한다.
  • object serialization나 transport에 추가적인 코드 작성이 필요없다.
  • Thrift IDL로 data 구조를 선언하는 방식으로 작성하면 object serialization과 transport 하는 코드를 자동적으로 생성해준다.
base type
  • bool A boolean value, true or false
  • byte A signed byte
  • i16 A 16-bit signed integer
  • i32 A 32-bit signed integer
  • i64 A 64-bit signed integer
  • double A 64-bit floating point number
  • string An encoding-agnostic text or binary string
  • unsigned integer types 은 제공 안함. 많은 언어에서 direct로 변환이 되질 않기 때문에
struct
  • c의 구조체와 비슷함
  • OOP 언어에선 class와 동일함
  • 강력한 typed field와 unique name identifier
Containers
  • Thrift containers are strongly typed containers that map to the most commonly used containers in common programming languages. They are annotated using the C++ template (or Java Generics) style. There are three types available:
  • list An ordered list of elements. Translates directly into an STL vector, Java ArrayList, or native array in script- ing languages. May contain duplicates.
  • set An unordered set of unique elements. Translates into an STL set, Java HashSet, set in Python, or native dictionary in PHP/Ruby.
  • map A map of strictly unique keys to values Translates into an STL map, Java HashMap, PHP associative array, or Python/Ruby dictionary.
example
Example
struct Example {  1:i32 number=10,  2:i64 bigNumber, 3:double decimals,  4:string name="thrifty" } 

참고자료