优化Client
This commit is contained in:
@@ -33,7 +33,7 @@ public class SncpClientCodecTest {
|
||||
InetSocketAddress remoteAddress = new InetSocketAddress("127.0.0.1", 3344);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
SncpClient client = new SncpClient("test", asyncGroup, 0, sncpAddress, new ClientAddress(remoteAddress), "TCP", Utility.cpus(), 16);
|
||||
SncpClientConnection conn = client.createClientConnection(1, asyncGroup.newTCPClientConnection());
|
||||
SncpClientConnection conn = client.createClientConnection(asyncGroup.newTCPClientConnection());
|
||||
SncpClientCodec codec = new SncpClientCodec(conn);
|
||||
List respResults = new ArrayList();
|
||||
try {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class SncpRequestParseTest {
|
||||
InetSocketAddress remoteAddress = new InetSocketAddress("127.0.0.1", 3344);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
SncpClient client = new SncpClient("test", asyncGroup, 0, sncpAddress, new ClientAddress(remoteAddress), "TCP", Utility.cpus(), 16);
|
||||
SncpClientConnection conn = client.createClientConnection(1, asyncGroup.newTCPClientConnection());
|
||||
SncpClientConnection conn = client.createClientConnection(asyncGroup.newTCPClientConnection());
|
||||
|
||||
SncpContext.SncpContextConfig config = new SncpContext.SncpContextConfig();
|
||||
config.logger = Logger.getLogger(SncpRequestParseTest.class.getSimpleName());
|
||||
|
||||
@@ -5,6 +5,7 @@ package org.redkale.test.sncp;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.redkale.service.AbstractService;
|
||||
import org.redkale.util.Times;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
@@ -14,26 +15,29 @@ import org.redkale.util.Utility;
|
||||
public class SncpSleepService extends AbstractService {
|
||||
|
||||
public CompletableFuture<String> sleep200() {
|
||||
return (CompletableFuture) CompletableFuture.supplyAsync(() -> {
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 接收sleep200");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Utility.sleep(200);
|
||||
System.out.println("执行完sleep200");
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep200");
|
||||
return "ok200";
|
||||
});
|
||||
}, getExecutor());
|
||||
}
|
||||
|
||||
public CompletableFuture<String> sleep300() {
|
||||
return (CompletableFuture) CompletableFuture.supplyAsync(() -> {
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 接收sleep300");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Utility.sleep(300);
|
||||
System.out.println("执行完sleep300");
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep300");
|
||||
return "ok300";
|
||||
});
|
||||
}, getExecutor());
|
||||
}
|
||||
|
||||
public CompletableFuture<String> sleep500() {
|
||||
return (CompletableFuture) CompletableFuture.supplyAsync(() -> {
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 接收sleep500");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Utility.sleep(500);
|
||||
System.out.println("执行完sleep500");
|
||||
System.out.println(Times.nowMillis() + " " + Thread.currentThread().getName() + " 执行完sleep500");
|
||||
return "ok500";
|
||||
});
|
||||
}, getExecutor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ package org.redkale.test.sncp;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.convert.bson.BsonConvert;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.AsyncIOGroup;
|
||||
import org.redkale.net.WorkThread;
|
||||
import org.redkale.net.client.ClientAddress;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.util.*;
|
||||
@@ -29,14 +31,17 @@ public class SncpSleepTest {
|
||||
public void run() throws Exception {
|
||||
System.out.println("------------------- 并发调用 -----------------------------------");
|
||||
final Application application = Application.create(true);
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
final ExecutorService workExecutor = WorkThread.createWorkExecutor(10, "Thread-Work-%s");
|
||||
final AsyncIOGroup asyncGroup = new AsyncIOGroup("Redkale-TestClient-IOThread-%s", workExecutor, 8192, 16);
|
||||
asyncGroup.start();
|
||||
final ResourceFactory resFactory = ResourceFactory.create();
|
||||
resFactory.register(Application.RESNAME_APP_EXECUTOR, ExecutorService.class, workExecutor);
|
||||
resFactory.register(JsonConvert.root());
|
||||
resFactory.register(BsonConvert.root());
|
||||
|
||||
//------------------------ 初始化 CService ------------------------------------
|
||||
SncpSleepService service = Sncp.createSimpleLocalService(SncpSleepService.class, resFactory);
|
||||
resFactory.inject(service);
|
||||
SncpServer server = new SncpServer(application, System.currentTimeMillis(), null, resFactory);
|
||||
server.getResourceFactory().register(application);
|
||||
server.addSncpServlet(service);
|
||||
@@ -60,6 +65,7 @@ public class SncpSleepTest {
|
||||
long e = System.currentTimeMillis() - s;
|
||||
System.out.println("耗时: " + e + " ms");
|
||||
server.shutdown();
|
||||
Assertions.assertTrue(e < 600);
|
||||
workExecutor.shutdown();
|
||||
Assertions.assertTrue(e < 900);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user