From 84a15afc9a898cf503fa95af7b9eb4802baedcf4 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Fri, 30 Mar 2018 08:39:15 +0800 Subject: [PATCH] --- src/META-INF/application-template.xml | 1 + src/org/redkale/boot/Application.java | 5 ++++- src/org/redkale/net/Transport.java | 6 ++---- src/org/redkale/net/TransportFactory.java | 15 ++++++++++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/META-INF/application-template.xml b/src/META-INF/application-template.xml index bfb6d4e80..280f0801c 100644 --- a/src/META-INF/application-template.xml +++ b/src/META-INF/application-template.xml @@ -85,6 +85,7 @@ 如果name是mimetype.property.开头的值将会在进程启动时进行MimeType.add("yyyy", "YYYYYY")操作。 load: 加载文件,多个用;隔开。 默认置入的system.property.的有: + System.setProperty("net.transport.poolmaxconns", "100"); System.setProperty("net.transport.pinginterval", "30"); System.setProperty("net.transport.checkinterval", "30"); System.setProperty("convert.json.tiny", "true"); diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index 72e60d766..de128dae7 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -315,7 +315,8 @@ public final class Application { }); } this.sncpTransportFactory = TransportFactory.create(transportExec, transportPool, transportGroup, (SSLContext) null, readTimeoutSecond, writeTimeoutSecond, strategy); - DefaultAnyValue tarnsportConf = DefaultAnyValue.create(TransportFactory.NAME_PINGINTERVAL, System.getProperty("net.transport.pinginterval", "30")) + DefaultAnyValue tarnsportConf = DefaultAnyValue.create(TransportFactory.NAME_POOLMAXCONNS, System.getProperty("net.transport.poolmaxconns", "100")) + .addValue(TransportFactory.NAME_PINGINTERVAL, System.getProperty("net.transport.pinginterval", "30")) .addValue(TransportFactory.NAME_CHECKINTERVAL, System.getProperty("net.transport.checkinterval", "30")); this.sncpTransportFactory.init(tarnsportConf, Sncp.PING_BUFFER, Sncp.PONG_BUFFER.remaining()); Thread.currentThread().setContextClassLoader(this.classLoader); @@ -356,7 +357,9 @@ public final class Application { public void init() throws Exception { System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "" + Runtime.getRuntime().availableProcessors() * 4); + System.setProperty("net.transport.poolmaxconns", "100"); System.setProperty("net.transport.pinginterval", "30"); + System.setProperty("net.transport.checkinterval", "30"); System.setProperty("convert.bson.tiny", "true"); System.setProperty("convert.json.tiny", "true"); System.setProperty("convert.bson.pool.size", "128"); diff --git a/src/org/redkale/net/Transport.java b/src/org/redkale/net/Transport.java index 76cbe6c25..a3dc55848 100644 --- a/src/org/redkale/net/Transport.java +++ b/src/org/redkale/net/Transport.java @@ -32,8 +32,6 @@ public final class Transport { public static final String DEFAULT_PROTOCOL = "TCP"; - protected static final int MAX_POOL_LIMIT = Runtime.getRuntime().availableProcessors() * 8; - protected static final boolean supportTcpNoDelay; static { @@ -395,13 +393,13 @@ public final class Transport { }); } - public static class TransportAddress { + public class TransportAddress { protected InetSocketAddress address; protected volatile long disabletime; //不可用时的时间, 为0表示可用 - protected final BlockingQueue conns = new ArrayBlockingQueue<>(MAX_POOL_LIMIT); + protected final BlockingQueue conns = new ArrayBlockingQueue<>(factory.poolmaxconns); protected final ConcurrentHashMap attributes = new ConcurrentHashMap<>(); diff --git a/src/org/redkale/net/TransportFactory.java b/src/org/redkale/net/TransportFactory.java index 0b70a30b5..6448fdcff 100644 --- a/src/org/redkale/net/TransportFactory.java +++ b/src/org/redkale/net/TransportFactory.java @@ -37,6 +37,8 @@ public class TransportFactory { @Comment("默认TCP写入超时秒数") public static int DEFAULT_WRITETIMEOUTSECOND = 6; + public static final String NAME_POOLMAXCONNS = "poolmaxconns"; + public static final String NAME_PINGINTERVAL = "pinginterval"; public static final String NAME_CHECKINTERVAL = "checkinterval"; @@ -62,12 +64,15 @@ public class TransportFactory { protected final List> transportReferences = new CopyOnWriteArrayList<>(); - //心跳周期, 单位:秒 - protected int pinginterval; + //连接池大小 + protected int poolmaxconns = Integer.getInteger("net.transport.poolmaxconns", 100); //检查不可用地址周期, 单位:秒 protected int checkinterval = Integer.getInteger("net.transport.checkinterval", 30); + //心跳周期, 单位:秒 + protected int pinginterval; + //TCP读取超时秒数 protected int readTimeoutSecond; @@ -106,8 +111,12 @@ public class TransportFactory { public void init(AnyValue conf, ByteBuffer pingBuffer, int pongLength) { if (conf != null) { - this.pinginterval = conf.getIntValue(NAME_PINGINTERVAL, 0); + this.poolmaxconns = conf.getIntValue(NAME_POOLMAXCONNS, this.poolmaxconns); + this.pinginterval = conf.getIntValue(NAME_PINGINTERVAL, this.pinginterval); this.checkinterval = conf.getIntValue(NAME_CHECKINTERVAL, this.checkinterval); + if (this.poolmaxconns < 2) this.poolmaxconns = 2; + if (this.pinginterval < 2) this.pinginterval = 2; + if (this.checkinterval < 2) this.checkinterval = 2; } this.scheduler = new ScheduledThreadPoolExecutor(1, (Runnable r) -> { final Thread t = new Thread(r, this.getClass().getSimpleName() + "-TransportFactoryTask-Thread");