Merge remote-tracking branch 'origin/master'

This commit is contained in:
ascrutae 2016-02-24 18:18:02 +08:00
commit 8f01480b95
4 changed files with 29 additions and 18 deletions

View File

@ -8,7 +8,8 @@ SkyWalking-Distributed Application Tracing System, 是一个对JAVA应用程序
* 张鑫   [亚信](http://www.asiainfo.com/) zhangxin10@asiainfo.com
# 交流群
QQ群392443393请注明“Sky Walking交流”
* QQ群392443393请注明“Sky Walking交流”
* 请各位使用者反馈下,都在哪些项目中使用。[点击进入](https://github.com/wu-sheng/sky-walking/issues/34)
# 整体架构图
![整体架构图](http://wu-sheng.github.io/sky-walking/sample-code/images/skywalkingClusterDeploy.jpeg)

View File

@ -4,9 +4,13 @@ import com.ai.cloud.skywalking.protocol.Span;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import static com.ai.cloud.skywalking.conf.Config.Buffer.POOL_SIZE;
public class ContextBuffer {
private static Logger logger = LogManager.getLogger(ContextBuffer.class);
private static BufferPool pool = new BufferPool();
@ -15,7 +19,11 @@ public class ContextBuffer {
}
public static void save(Span span) {
pool.save(span);
try{
pool.save(span);
}catch(Throwable t){
logger.error("save span error.", t);
}
}

View File

@ -21,11 +21,14 @@ public class AtomicRangeInteger extends Number implements java.io.Serializable {
*
* @param initialValue
* the initial value
* @param endValue
*
* AtomicRangeInteger在startValue和maxValue循环取值 startValue <= value < maxValue
*/
public AtomicRangeInteger(int startValue, int endValue) {
public AtomicRangeInteger(int startValue, int maxValue) {
value = new AtomicInteger(startValue);
this.startValue = startValue;
this.endValue = endValue;
this.endValue = maxValue - 1;
}
/**
@ -35,11 +38,8 @@ public class AtomicRangeInteger extends Number implements java.io.Serializable {
*/
public final int getAndIncrement() {
for (;;) {
int current = get();
int next = current + 1;
if (next >= this.endValue) {
next = this.startValue;
}
int current = value.get();
int next = current >= this.endValue ? this.startValue : current + 1;
if (value.compareAndSet(current, next))
return current;
}

View File

@ -9,6 +9,10 @@ import junit.framework.TestCase;
import com.ai.cloud.skywalking.util.AtomicRangeInteger;
public class AtomicRangeIntegerTest extends TestCase{
static String[] buffer = new String[5000];
static AtomicRangeInteger ari = new AtomicRangeInteger(0, buffer.length);
public void testGet(){
AtomicRangeInteger ari = new AtomicRangeInteger(0, 12);
for(int i = 0; i < 51; i++){
@ -36,22 +40,20 @@ public class AtomicRangeIntegerTest extends TestCase{
}
class RangeIntegerThread extends Thread{
private static String[] buffer = new String[500000000];
private static AtomicRangeInteger ari = new AtomicRangeInteger(0, buffer.length);
@Override
public void run(){
while(true){
int i = ari.getAndIncrement();
int i = AtomicRangeIntegerTest.ari.getAndIncrement();
if(i % 10000000 == 0){
System.out.println(ari.get());
System.out.println(AtomicRangeIntegerTest.ari.get());
}
if(i >= buffer.length - 100000){
if(AtomicRangeIntegerTest.buffer[i] != null){
System.out.println("end at index:" + i + "," + AtomicRangeIntegerTest.buffer[i]);
break;
}else{
System.out.println("at index:" + i);
AtomicRangeIntegerTest.buffer[i] = "string";
}
Assert.assertNull(buffer[i]);
buffer[i] = "string";
}
}
}