提交 c69b02d2 编写于 作者: Z zhangxin10

1. 解决不重连的问题

上级 7a270e48
...@@ -40,6 +40,13 @@ public class DataSenderFactory { ...@@ -40,6 +40,13 @@ public class DataSenderFactory {
} }
public static DataSender getSender() { 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())); return availableSenders.get(ThreadLocalRandom.current().nextInt(0, availableSenders.size()));
} }
...@@ -70,7 +77,6 @@ public class DataSenderFactory { ...@@ -70,7 +77,6 @@ public class DataSenderFactory {
public void run() { public void run() {
while (true) { while (true) {
//当可用的Sender的数量和保存的地址的比例不在1:2,则不创建
for (SocketAddress socketAddress : unUsedSocketAddresses) { for (SocketAddress socketAddress : unUsedSocketAddresses) {
if (availableSenders.size() >= avaiableSize) { if (availableSenders.size() >= avaiableSize) {
break; break;
......
...@@ -37,7 +37,7 @@ public class SpanBufferTest { ...@@ -37,7 +37,7 @@ public class SpanBufferTest {
@Parameterized.Parameters @Parameterized.Parameters
public static Collection<Integer[]> getParams() { public static Collection<Integer[]> getParams() {
return Arrays.asList(new Integer[][]{ return Arrays.asList(new Integer[][]{
{2000, 10}, {1, 10001},
// {2000, 100000, 5, 27000, 3}, // {2000, 100000, 5, 27000, 3},
// {2000, 100000, 5, 24000, 3}, // {2000, 100000, 5, 24000, 3},
// {2000, 100000, 5, 20000, 2}, // {2000, 100000, 5, 20000, 2},
...@@ -50,33 +50,24 @@ public class SpanBufferTest { ...@@ -50,33 +50,24 @@ public class SpanBufferTest {
@Test @Test
public void testSave() throws Exception { public void testSave() throws Exception {
System.out.println(threadSize + " " + sizeCount); while (true) {
CountDownLatch countDownLatch = new CountDownLatch(threadSize); System.out.println(threadSize + " " + sizeCount);
long start = System.currentTimeMillis(); CountDownLatch countDownLatch = new CountDownLatch(threadSize);
long sleepTime = 1000; long start = System.currentTimeMillis();
for (int i = 0; i < threadSize; i++) { long sleepTime = 1000;
if (i % 100 == 0) { for (int i = 0; i < threadSize; i++) {
sleepTime = sleepTime / 2; if (i % 100 == 0) {
if (sleepTime == 0){ sleepTime = sleepTime / 2;
sleepTime = 5; if (sleepTime == 0) {
sleepTime = 5;
}
Thread.sleep(sleepTime);
} }
Thread.sleep(sleepTime); new ContextBufferThread(countDownLatch, sizeCount).start();
} }
new ContextBufferThread(countDownLatch, sizeCount).start(); countDownLatch.await();
}
countDownLatch.await(); Thread.sleep(5000L);
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
package com.ai.cloud.skywalking.sender; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Properties;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
...@@ -21,12 +27,16 @@ public class SenderTest { ...@@ -21,12 +27,16 @@ public class SenderTest {
@Parameterized.Parameters @Parameterized.Parameters
public static Collection<Integer[]> getParams() { public static Collection<Integer[]> getParams() {
return Arrays.asList(new Integer[][]{ return Arrays.asList(new Integer[][]{
{1, 100}, {1, 10000000},
}); });
} }
@Test @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); CountDownLatch countDownLatch = new CountDownLatch(threadSize * countSize);
for (int i = 0; i < threadSize; i++) { for (int i = 0; i < threadSize; i++) {
Thread.sleep(1L); Thread.sleep(1L);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册