init
This commit is contained in:
parent
97897db22c
commit
538f42181f
@ -31,7 +31,7 @@ public class Constants {
|
|||||||
* 两个标识ID组合在分布式环境中必须唯一
|
* 两个标识ID组合在分布式环境中必须唯一
|
||||||
*/
|
*/
|
||||||
public static long DATACENTER_ID = 1;
|
public static long DATACENTER_ID = 1;
|
||||||
public static long MACHINES_SIGN = 1;
|
public static long MACHINES_ID = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流量控制,表示每秒处理的并发数
|
* 流量控制,表示每秒处理的并发数
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Tue Aug 14 15:16:52 CST 2018
|
#Tue Aug 14 18:31:53 CST 2018
|
||||||
version=1.0-SNAPSHOT
|
version=1.0-SNAPSHOT
|
||||||
groupId=cn.ceres.did
|
groupId=cn.ceres.did
|
||||||
artifactId=did-common
|
artifactId=did-common
|
||||||
|
@ -9,7 +9,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步请求压测
|
* 异步请求压测
|
||||||
@ -23,7 +22,7 @@ public class DidSdkPressAsyncTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pressAsyncTest() throws Exception {
|
public void pressAsyncTest() throws Exception {
|
||||||
SdkClient client = new SdkClient();
|
SdkClient client = new SdkClient("10.19.248.200",30581);
|
||||||
client.init();
|
client.init();
|
||||||
client.start();
|
client.start();
|
||||||
|
|
||||||
@ -46,15 +45,16 @@ public class DidSdkPressAsyncTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// countDownLatch.await(10, TimeUnit.SECONDS);
|
||||||
|
countDownLatch.await();
|
||||||
end = System.currentTimeMillis();
|
end = System.currentTimeMillis();
|
||||||
cast = (end - start);
|
cast = (end - start);
|
||||||
allcast += cast;
|
allcast += cast;
|
||||||
countDownLatch.await(10, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
logger.info("invokeAsync test num is: {}, cast time: {} millsec, throughput: {} send/millsec", NUM, cast, (double) NUM / cast);
|
logger.info("invokeAsync test num is: {}, cast time: {} millsec, throughput: {} send/millsec", NUM, cast, (double) NUM / cast);
|
||||||
amount += NUM;
|
amount += NUM;
|
||||||
NUM = NUM + 5000;
|
// NUM = NUM + 5000;
|
||||||
TimeUnit.SECONDS.sleep(2);
|
// TimeUnit.SECONDS.sleep(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("invokeAsync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);
|
logger.info("invokeAsync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);
|
||||||
|
@ -6,8 +6,6 @@ import org.junit.Test;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步请求压测
|
* 同步请求压测
|
||||||
*
|
*
|
||||||
@ -19,7 +17,7 @@ public class DidSdkPressSyncTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pressSyncTest() throws Exception {
|
public void pressSyncTest() throws Exception {
|
||||||
SdkClient client = new SdkClient();
|
SdkClient client = new SdkClient("10.19.248.200",30581);
|
||||||
client.init();
|
client.init();
|
||||||
client.start();
|
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);
|
logger.info("invokeSync test num is: {}, cast time: {} millsec, throughput: {} send/millsec", NUM, cast, (double) NUM / cast);
|
||||||
|
|
||||||
amount += NUM;
|
amount += NUM;
|
||||||
NUM += 5000;
|
// NUM += 5000;
|
||||||
TimeUnit.SECONDS.sleep(2);
|
// TimeUnit.SECONDS.sleep(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("invokeSync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);
|
logger.info("invokeSync test all num is: {}, all cast time: {} millsec, all throughput: {} send/millsec", amount, allcast, (double) amount / allcast);
|
||||||
|
@ -13,11 +13,11 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @author ehlxr
|
* @author ehlxr
|
||||||
*/
|
*/
|
||||||
public class DidSdkTest {
|
public class DidSdkTest {
|
||||||
private static final int NUM = 100;
|
private static final int NUM = 10;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void didSdkTest() throws Exception {
|
public void didSdkTest() throws Exception {
|
||||||
SdkClient client = new SdkClient();
|
SdkClient client = new SdkClient("10.19.248.200", 30581);
|
||||||
client.init();
|
client.init();
|
||||||
client.start();
|
client.start();
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Tue Aug 14 15:16:54 CST 2018
|
#Tue Aug 14 18:31:54 CST 2018
|
||||||
version=1.0-SNAPSHOT
|
version=1.0-SNAPSHOT
|
||||||
groupId=cn.ceres.did
|
groupId=cn.ceres.did
|
||||||
artifactId=did-sdk
|
artifactId=did-sdk
|
||||||
|
@ -27,9 +27,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -42,10 +42,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
@ -17,7 +17,7 @@ public class ServerStarter {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
long datacenterId = Constants.DATACENTER_ID;
|
long datacenterId = Constants.DATACENTER_ID;
|
||||||
long machineId = Constants.MACHINES_SIGN;
|
long machineId = Constants.MACHINES_ID;
|
||||||
|
|
||||||
if (args != null && args.length == 2) {
|
if (args != null && args.length == 2) {
|
||||||
datacenterId = Long.valueOf(args[0]);
|
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"));
|
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);
|
logger.info("SnowFlake datacenterId is: {}, machineId is: {}", datacenterId, machineId);
|
||||||
|
|
||||||
final SnowFlake snowFlake = new SnowFlake(datacenterId, machineId);
|
final SnowFlake snowFlake = new SnowFlake(datacenterId, machineId);
|
||||||
|
@ -25,7 +25,7 @@ public class HttpServer extends BaseServer {
|
|||||||
|
|
||||||
public HttpServer(SnowFlake snowFlake) {
|
public HttpServer(SnowFlake snowFlake) {
|
||||||
this.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
|
@Override
|
||||||
|
@ -39,25 +39,25 @@ public class HttpServerHandler extends SimpleChannelInboundHandler<FullHttpReque
|
|||||||
String uri = getUriNoSprit(request);
|
String uri = getUriNoSprit(request);
|
||||||
logger.info("request uri is: {}", uri);
|
logger.info("request uri is: {}", uri);
|
||||||
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||||
if (Constants.HTTP_REQUEST.equals(uri)) {
|
// if (Constants.HTTP_REQUEST.equals(uri)) {
|
||||||
if (semaphore.tryAcquire(Constants.ACQUIRE_TIMEOUTMILLIS, TimeUnit.MILLISECONDS)) {
|
if (semaphore.tryAcquire(Constants.ACQUIRE_TIMEOUTMILLIS, TimeUnit.MILLISECONDS)) {
|
||||||
try {
|
try {
|
||||||
long id = snowFlake.nextId();
|
long id = snowFlake.nextId();
|
||||||
logger.info("HttpServerHandler id is: {}", id);
|
logger.info("HttpServerHandler id is: {}", id);
|
||||||
response.content().writeBytes(("" + id).getBytes());
|
response.content().writeBytes(("" + id).getBytes());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
semaphore.release();
|
semaphore.release();
|
||||||
logger.error("HttpServerHandler error", e);
|
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);
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class SdkServer extends BaseServer {
|
|||||||
|
|
||||||
public SdkServer(SnowFlake snowFlake) {
|
public SdkServer(SnowFlake snowFlake) {
|
||||||
this.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
|
@Override
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Tue Aug 14 15:16:53 CST 2018
|
#Tue Aug 14 18:32:03 CST 2018
|
||||||
version=1.0-SNAPSHOT
|
version=1.0-SNAPSHOT
|
||||||
groupId=cn.ceres.did
|
groupId=cn.ceres.did
|
||||||
artifactId=did-server
|
artifactId=did-server
|
||||||
|
Loading…
Reference in New Issue
Block a user