From c69b02d2128acbc16688353bff0864a9e97fa54c Mon Sep 17 00:00:00 2001 From: zhangxin10 Date: Wed, 11 Nov 2015 22:17:52 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=A7=A3=E5=86=B3=E4=B8=8D=E9=87=8D?= =?UTF-8?q?=E8=BF=9E=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skywalking/sender/DataSenderFactory.java | 8 +++- .../skywalking/buffer/SpanBufferTest.java | 43 ++++++++----------- .../cloud/skywalking/sender/SenderTest.java | 14 +++++- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/sender/DataSenderFactory.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/sender/DataSenderFactory.java index 09ba7acc4..700904982 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/sender/DataSenderFactory.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/sender/DataSenderFactory.java @@ -40,6 +40,13 @@ public class DataSenderFactory { } public static DataSender getSender() { + while(availableSenders.size() <= 0){ + try { + Thread.sleep(2000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } return availableSenders.get(ThreadLocalRandom.current().nextInt(0, availableSenders.size())); } @@ -70,7 +77,6 @@ public class DataSenderFactory { public void run() { while (true) { - //当可用的Sender的数量和保存的地址的比例不在1:2,则不创建 for (SocketAddress socketAddress : unUsedSocketAddresses) { if (availableSenders.size() >= avaiableSize) { break; diff --git a/skywalking-api/src/test/java/com/ai/cloud/skywalking/buffer/SpanBufferTest.java b/skywalking-api/src/test/java/com/ai/cloud/skywalking/buffer/SpanBufferTest.java index ef03414ff..6ee952a58 100644 --- a/skywalking-api/src/test/java/com/ai/cloud/skywalking/buffer/SpanBufferTest.java +++ b/skywalking-api/src/test/java/com/ai/cloud/skywalking/buffer/SpanBufferTest.java @@ -37,7 +37,7 @@ public class SpanBufferTest { @Parameterized.Parameters public static Collection getParams() { return Arrays.asList(new Integer[][]{ - {2000, 10}, + {1, 10001}, // {2000, 100000, 5, 27000, 3}, // {2000, 100000, 5, 24000, 3}, // {2000, 100000, 5, 20000, 2}, @@ -50,33 +50,24 @@ public class SpanBufferTest { @Test public void testSave() throws Exception { - System.out.println(threadSize + " " + sizeCount); - CountDownLatch countDownLatch = new CountDownLatch(threadSize); - long start = System.currentTimeMillis(); - long sleepTime = 1000; - for (int i = 0; i < threadSize; i++) { - if (i % 100 == 0) { - sleepTime = sleepTime / 2; - if (sleepTime == 0){ - sleepTime = 5; + while (true) { + System.out.println(threadSize + " " + sizeCount); + CountDownLatch countDownLatch = new CountDownLatch(threadSize); + long start = System.currentTimeMillis(); + long sleepTime = 1000; + for (int i = 0; i < threadSize; i++) { + if (i % 100 == 0) { + sleepTime = sleepTime / 2; + if (sleepTime == 0) { + sleepTime = 5; + } + Thread.sleep(sleepTime); } - Thread.sleep(sleepTime); + new ContextBufferThread(countDownLatch, sizeCount).start(); } - new ContextBufferThread(countDownLatch, sizeCount).start(); + countDownLatch.await(); + + Thread.sleep(5000L); } - countDownLatch.await(); - CountDownLatch countDownLatchA = new CountDownLatch(threadSize); - sleepTime = 1000; - for (int i = 0; i < threadSize; i++) { - if (i % 100 == 0) { - sleepTime = sleepTime / 2; - if (sleepTime == 0){ - sleepTime = 5; - } - Thread.sleep(sleepTime); - } - new ContextBufferThreadA(countDownLatchA, sizeCount).start(); - } - countDownLatchA.await(); } } \ No newline at end of file diff --git a/skywalking-api/src/test/java/com/ai/cloud/skywalking/sender/SenderTest.java b/skywalking-api/src/test/java/com/ai/cloud/skywalking/sender/SenderTest.java index 9779163bf..d50b5f8a5 100644 --- a/skywalking-api/src/test/java/com/ai/cloud/skywalking/sender/SenderTest.java +++ b/skywalking-api/src/test/java/com/ai/cloud/skywalking/sender/SenderTest.java @@ -1,11 +1,17 @@ package com.ai.cloud.skywalking.sender; +import com.ai.cloud.skywalking.buffer.ContextBuffer; +import com.ai.cloud.skywalking.conf.Config; +import com.ai.cloud.skywalking.conf.ConfigInitializer; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; import java.util.Collection; +import java.util.Properties; import java.util.concurrent.CountDownLatch; @RunWith(Parameterized.class) @@ -21,12 +27,16 @@ public class SenderTest { @Parameterized.Parameters public static Collection getParams() { return Arrays.asList(new Integer[][]{ - {1, 100}, + {1, 10000000}, }); } @Test - public void testSender() throws InterruptedException { + public void testSender() throws InterruptedException, IllegalAccessException, IOException { + InputStream inputStream = ContextBuffer.class.getResourceAsStream("/sky-walking.auth"); + Properties properties = new Properties(); + properties.load(inputStream); + ConfigInitializer.initialize(properties, Config.class); CountDownLatch countDownLatch = new CountDownLatch(threadSize * countSize); for (int i = 0; i < threadSize; i++) { Thread.sleep(1L);