Skip to content

Instantly share code, notes, and snippets.

@coderplay
coderplay / DragonVertex.java
Created January 30, 2012 10:05
DragonVertexTest
Configuration conf = getConf();
conf.setInt(INT_PROPERTY, 1);
conf.set(STRING_PROPERTY, "VALUE");
conf.set(GraphJobConfig.PROPERTY, "GRAPHJOB_VALUE");
GraphJob job = GraphJob.getInstance(conf);
job.setJobName("First Graph Job");
DragonVertex source = new DragonVertex.Builder("source")
.producer(EventProducer.class)
@coderplay
coderplay / AsyncMapRunner.java
Created March 2, 2012 02:42
Asynchronous Hadoop MapRunner
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@coderplay
coderplay / TestWatchService.java
Created March 3, 2012 05:21
HDFS WatchService
package com.taobao.dw.hdfs.file;
import org.apache.hadoop.fs.Path;
public class TestWatchService {
public static void main(String[] args) throws IOException {
AbstractWatchService service = WatchServiceFactory.newWatchService();
service.register(new Path("/user/min/"),
StandardWatchEventKinds.ENTRY_CREATE);
while (true) {
@coderplay
coderplay / IncrementVolatileLong.java
Created May 16, 2012 06:02
what every java programmer should know about cpu
public class IncrementVolatileLong {
private static volatile long value;
public static void increment() {
while (value < 500000000L) {
value++;
}
}
@coderplay
coderplay / ShowAssembly
Created May 16, 2012 09:58
Memory Barrier
$ java -XX:+UnlockDiagnosticVMOptions -XX:PrintAssemblyOptions=hsdis-print-bytes -XX:CompileCommand=print,X.f X
CompilerOracle: print X.f
Java HotSpot(TM) Server VM warning: printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output
Compiled (c2) 5066 1 nmethod X::f (56 bytes)
total in heap [0xb3a1e188,0xb3a1e394] = 524
relocation [0xb3a1e254,0xb3a1e264] = 16
main code [0xb3a1e280,0xb3a1e2c0] = 64
stub code [0xb3a1e2c0,0xb3a1e2d0] = 16
oops [0xb3a1e2d0,0xb3a1e2d4] = 4
scopes data [0xb3a1e2d4,0xb3a1e300] = 44
@coderplay
coderplay / jobsubmission.md
Created May 25, 2012 16:35
Dragon job submission flow path
  • check first vertex has specified input data path or not
  • fetch a new application id from resource manager
  • get secret keys and tokens from namenodes and store them into TokenCache
  • copy local files/archives into remote filesystem (e.g. hdfs)
  • write job config file to submit dir
  • write job description file to submit dir
  • get the security token of the jobSubmitDir and store in Credentials
  • create submission context for the job
  • create launch context for application master
@coderplay
coderplay / TestKryo.java
Created June 7, 2012 09:51
Kryo BigObject Test
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import org.objenesis.strategy.StdInstantiatorStrategy;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Output;
public class TestKryo {
public static class Simple implements java.io.Serializable{
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@coderplay
coderplay / SegmentedEratosthenes.java
Created September 13, 2012 03:59
SegmentedEratosthenes
import java.util.BitSet;
/**
* Shamelessly copied some code from <a
* href="mailto:zhong.lunfu@gmail.com">zhongl<a>.
*
* <p>
* The basic idea of a segmented sieve is to choose the sieving primes less than
* the square root of n, choose a reasonably large segment size that
* nevertheless fits in memory, and then sieve each of the segments in turn,