This commit is contained in:
ehlxr 2018-08-14 18:37:34 +08:00
parent 97897db22c
commit 538f42181f
13 changed files with 34 additions and 43 deletions

View File

@ -31,7 +31,7 @@ public class Constants {
* 两个标识ID组合在分布式环境中必须唯一
*/
public static long DATACENTER_ID = 1;
public static long MACHINES_SIGN = 1;
public static long MACHINES_ID = 1;
/**
* 流量控制表示每秒处理的并发数

View File

@ -1,5 +1,5 @@
#Generated by Maven
#Tue Aug 14 15:16:52 CST 2018
#Tue Aug 14 18:31:53 CST 2018
version=1.0-SNAPSHOT
groupId=cn.ceres.did
artifactId=did-common

View File

@ -9,7 +9,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* 异步请求压测
@ -23,7 +22,7 @@ public class DidSdkPressAsyncTest {
@Test
public void pressAsyncTest() throws Exception {
SdkClient client = new SdkClient();
SdkClient client = new SdkClient("10.19.248.200",30581);
client.init();
client.start();
@ -46,15 +45,16 @@ public class DidSdkPressAsyncTest {
});
}
// countDownLatch.await(10, TimeUnit.SECONDS);
countDownLatch.await();
end = System.currentTimeMillis();
cast = (end - start);
allcast += cast;
countDownLatch.await(10, TimeUnit.SECONDS);
logger.info("invokeAsync test num is: {}, cast time: {} millsec, throughput: {} send/millsec", NUM, cast, (double) NUM / cast);
amount += NUM;
NUM = NUM + 5000;
TimeUnit.SECONDS.sleep(2);
// NUM = NUM + 5000;
// TimeUnit.SECONDS.sleep(2);
}
logger.info("invokeAsync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);

View File

@ -6,8 +6,6 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
/**
* 同步请求压测
*
@ -19,7 +17,7 @@ public class DidSdkPressSyncTest {
@Test
public void pressSyncTest() throws Exception {
SdkClient client = new SdkClient();
SdkClient client = new SdkClient("10.19.248.200",30581);
client.init();
client.start();
@ -43,8 +41,8 @@ public class DidSdkPressSyncTest {
logger.info("invokeSync test num is: {}, cast time: {} millsec, throughput: {} send/millsec", NUM, cast, (double) NUM / cast);
amount += NUM;
NUM += 5000;
TimeUnit.SECONDS.sleep(2);
// NUM += 5000;
// TimeUnit.SECONDS.sleep(2);
}
logger.info("invokeSync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);

View File

@ -13,11 +13,11 @@ import java.util.concurrent.TimeUnit;
* @author ehlxr
*/
public class DidSdkTest {
private static final int NUM = 100;
private static final int NUM = 10;
@Test
public void didSdkTest() throws Exception {
SdkClient client = new SdkClient();
SdkClient client = new SdkClient("10.19.248.200", 30581);
client.init();
client.start();

View File

@ -1,5 +1,5 @@
#Generated by Maven
#Tue Aug 14 15:16:54 CST 2018
#Tue Aug 14 18:31:54 CST 2018
version=1.0-SNAPSHOT
groupId=cn.ceres.did
artifactId=did-sdk

View File

@ -27,9 +27,6 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -42,10 +42,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -17,7 +17,7 @@ public class ServerStarter {
public static void main(String[] args) {
long datacenterId = Constants.DATACENTER_ID;
long machineId = Constants.MACHINES_SIGN;
long machineId = Constants.MACHINES_ID;
if (args != null && args.length == 2) {
datacenterId = Long.valueOf(args[0]);
@ -25,7 +25,7 @@ public class ServerStarter {
}
datacenterId = "".equals(Constants.getEnv("DATACENTER_ID")) ? datacenterId : Long.valueOf(Constants.getEnv("DATACENTER_ID"));
machineId = "".equals(Constants.getEnv("MACHINES_SIGN")) ? machineId : Long.valueOf(Constants.getEnv("MACHINES_SIGN"));
machineId = "".equals(Constants.getEnv("MACHINES_ID")) ? machineId : Long.valueOf(Constants.getEnv("MACHINES_ID"));
logger.info("SnowFlake datacenterId is: {}, machineId is: {}", datacenterId, machineId);
final SnowFlake snowFlake = new SnowFlake(datacenterId, machineId);

View File

@ -25,7 +25,7 @@ public class HttpServer extends BaseServer {
public HttpServer(SnowFlake snowFlake) {
this.snowFlake = snowFlake;
this.port = Constants.HTTP_PORT;
this.port = "".equals(Constants.getEnv("HTTP_PORT")) ? Constants.HTTP_PORT : Integer.valueOf(Constants.getEnv("HTTP_PORT"));
}
@Override

View File

@ -39,25 +39,25 @@ public class HttpServerHandler extends SimpleChannelInboundHandler<FullHttpReque
String uri = getUriNoSprit(request);
logger.info("request uri is: {}", uri);
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
if (Constants.HTTP_REQUEST.equals(uri)) {
if (semaphore.tryAcquire(Constants.ACQUIRE_TIMEOUTMILLIS, TimeUnit.MILLISECONDS)) {
try {
long id = snowFlake.nextId();
logger.info("HttpServerHandler id is: {}", id);
response.content().writeBytes(("" + id).getBytes());
} catch (Exception e) {
semaphore.release();
logger.error("HttpServerHandler error", e);
}
} else {
String info = String.format("HttpServerHandler tryAcquire semaphore timeout, %dms, waiting thread " + "nums: %d availablePermit: %d",
Constants.ACQUIRE_TIMEOUTMILLIS, this.semaphore.getQueueLength(), this.semaphore.availablePermits());
logger.warn(info);
throw new Exception(info);
// if (Constants.HTTP_REQUEST.equals(uri)) {
if (semaphore.tryAcquire(Constants.ACQUIRE_TIMEOUTMILLIS, TimeUnit.MILLISECONDS)) {
try {
long id = snowFlake.nextId();
logger.info("HttpServerHandler id is: {}", id);
response.content().writeBytes(("" + id).getBytes());
} catch (Exception e) {
semaphore.release();
logger.error("HttpServerHandler error", e);
}
} else {
response.content().writeBytes(("Unsupported uri: " + uri).getBytes());
String info = String.format("HttpServerHandler tryAcquire semaphore timeout, %dms, waiting thread " + "nums: %d availablePermit: %d",
Constants.ACQUIRE_TIMEOUTMILLIS, this.semaphore.getQueueLength(), this.semaphore.availablePermits());
logger.warn(info);
throw new Exception(info);
}
// } else {
// response.content().writeBytes(("Unsupported uri: " + uri).getBytes());
// }
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}

View File

@ -18,7 +18,7 @@ public class SdkServer extends BaseServer {
public SdkServer(SnowFlake snowFlake) {
this.snowFlake = snowFlake;
this.port = Constants.SDKS_PORT;
this.port = "".equals(Constants.getEnv("SDKS_PORT")) ? Constants.SDKS_PORT : Integer.valueOf(Constants.getEnv("SDKS_PORT"));
}
@Override

View File

@ -1,5 +1,5 @@
#Generated by Maven
#Tue Aug 14 15:16:53 CST 2018
#Tue Aug 14 18:32:03 CST 2018
version=1.0-SNAPSHOT
groupId=cn.ceres.did
artifactId=did-server