2010年3月10日水曜日

EC2 AutoScaling(自動スケーリング設定)

EC2を自動スケーリングするように設定した。
てっきり、CloudWatchでモニタリングして自分でインスタンス立ち上げて
ロードバランサに割り当てるもんだと思ってたがAutoScaling設定しとけば
勝手にやってくれるのね。

ってことで、以下のような感じで。

コンフィグ設定
サンプルパラメータは名前 AMI名 AMIのタイプ
# as-create-launch-config test-lc --image-id ami-TEST --instance-type m1.large

スケーリンググループ作成
サンプルパラメータは名前 コンフィグ名 ゾーン 最小構成 最大構成 ロードバランサ名
ロードバランサに割り当てる場合は--load-balancersを指定する。
(ロードバランサは事前に作成しておく)
# as-create-auto-scaling-group test-sgroup --launch-configuration test-lc --availability-zones us-east-1b --min-size 1 --max-size 5 --load-balancers test-lb

トリガ設定
サンプルパラメータは名前 スケーリンググループ名 モニタリング項目 閾値の項目 モニタリングの設定 モニタリング間隔 閾値を下回った場合のスケール 閾値を上回った場合のスケール 閾値を越えた場合の実行秒
# as-create-or-update-trigger test-trigger --auto-scaling-group test-sgroup --measure CPUUtilization --statistic Average --dimensions "AutoScalingGroupName=test-sgroup" --period 60 --lower-threshold 20 --upper-threshold 80 --lower-breach-increment=-1 --upper-breach-increment 1 --breach-duration 120


その他確認コマンドは

コンフィグ設定の確認
# as-describe-launch-configs

スケーリンググループの確認
# as-describe-auto-scaling-groups

トリガの確認
パラメータにスケーリンググループ名
# as-describe-triggers test-sgroup

細かいマニュアルは --help で。

2010年3月6日土曜日

また本買ってもうた

いや、存在は知ってたけどなんか買う気がおきず
立ち読みしたら気になったもので。。。

2010年2月28日日曜日

本いろいろ

久しぶりにまとめて本を買った。

1冊目はデブサミで@yoshioriが紹介していて
おもしろそうだと思い即購入。



2冊目はtwitterでも結構話が出ていて第2版になっていたので購入。




しばらくは電車で暇を持て余さなくて済みそうだ。。。

2010年2月9日火曜日

MapReduceのテスト

MapReduceのテストはHadopp本にはMockitoを使う良いあるよと書いております。
でも、やはり0.19.xが前提なので情報が古い。
ってことで、0.20.xで以下のような感じで書いてみた。



package example.test;

import java.util.Arrays;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;

import static org.mockito.Mockito.*;

import junit.framework.TestCase;

public class CountTest extends TestCase {
    @SuppressWarnings("unchecked")
    public void testMapLongWritableTextContext() {
        // Mapのテスト
        Map map = new Map();
        Mapper.Context map_context = mock(Mapper.Context.class);

        Text value = null;
        try {
            value = new Text("test1");
            map.map(null, value, map_context);
            verify(map_context, times(1)).write(new Text("test1"), new LongWritable(1));

            value = new Text("test2");
            map.map(null, value, map_context);
            verify(map_context, times(0)).write(new Text("test1"), new LongWritable(0));
        } catch (Exception e) {
            fail(e.getMessage());
        }


        // Reduceのテスト
        Reduce reduce = new Reduce();
        Reducer.Context red_context = mock(Reducer.Context.class);

        Text key = null;
        Iterable<longwritable> values;
        try {
            key = new Text("test1");
            values = Arrays.asList(new LongWritable(2));
            reduce.reduce(key, values, red_context);
            verify(red_context, times(1)).write(new Text("test1"), new LongWritable(2));

            key = new Text("test2");
            values = Arrays.asList(new LongWritable(2), new LongWritable(2));
            reduce.reduce(key, values, red_context);
            verify(red_context, times(1)).write(new Text("test2"), new LongWritable(4));
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
}

2010年2月2日火曜日

HDFSへの書き込み/読み込み方法

下記のような感じで。

Configuration conf = new Configuration();
// ユーザを指定する場合
conf.set(UnixUserGroupInformation.UGI_PROPERTY_NAME, "hoge,supergroup");
FileSystem fs = FileSystem.get(new URI("hdfs://hoge:9000/"), conf);

// ディレクトリの作成など
try {
  fs.getFileStatus(new Path("hoge"));
} catch (FileNotFoundException e) {
  fs.mkdirs(new Path("hoge"));
}

// ファイルへの出力
// ex. 最後のフラグは上書き
FSDataOutputStream dos = fs.create(new Path("hoge/hoge.txt"), true);
dos.writeChars("テスト\n");
dos.close();

みたいに。