ByteBufferPool
This commit is contained in:
@@ -52,6 +52,7 @@ import org.redkale.source.*;
|
|||||||
import org.redkale.source.spi.SourceModuleEngine;
|
import org.redkale.source.spi.SourceModuleEngine;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.AnyValueWriter;
|
import org.redkale.util.AnyValueWriter;
|
||||||
|
import org.redkale.util.ByteBufferPool;
|
||||||
import org.redkale.util.Creator;
|
import org.redkale.util.Creator;
|
||||||
import org.redkale.util.Environment;
|
import org.redkale.util.Environment;
|
||||||
import org.redkale.util.Redkale;
|
import org.redkale.util.Redkale;
|
||||||
@@ -810,11 +811,12 @@ public final class Application {
|
|||||||
/** 设置WorkExecutor */
|
/** 设置WorkExecutor */
|
||||||
private void initWorkExecutor() {
|
private void initWorkExecutor() {
|
||||||
int bufferCapacity = 32 * 1024;
|
int bufferCapacity = 32 * 1024;
|
||||||
int bufferPoolSize = Utility.cpus() * 8;
|
int bufferPoolSize = ByteBufferPool.DEFAULT_BUFFER_POOL_SIZE;
|
||||||
final AnyValue executorConf = config.getAnyValue("executor", true);
|
final AnyValue executorConf = config.getAnyValue("executor", true);
|
||||||
StringBuilder executorLog = new StringBuilder();
|
StringBuilder executorLog = new StringBuilder();
|
||||||
|
|
||||||
final int workThreads = Math.max(Utility.cpus(), executorConf.getIntValue("threads", Utility.cpus() * 10));
|
int confThreads = executorConf.getIntValue("threads", WorkThread.DEFAULT_WORK_POOL_SIZE);
|
||||||
|
final int workThreads = Math.max(Utility.cpus(), confThreads);
|
||||||
// 指定threads则不使用虚拟线程池
|
// 指定threads则不使用虚拟线程池
|
||||||
this.workExecutor = executorConf.getValue("threads") != null
|
this.workExecutor = executorConf.getValue("threads") != null
|
||||||
? WorkThread.createExecutor(workThreads, "Redkale-WorkThread-%s")
|
? WorkThread.createExecutor(workThreads, "Redkale-WorkThread-%s")
|
||||||
@@ -832,7 +834,7 @@ public final class Application {
|
|||||||
executorLog.append(", clientWorkExecutor: [workExecutor]");
|
executorLog.append(", clientWorkExecutor: [workExecutor]");
|
||||||
} else {
|
} else {
|
||||||
// 给所有client给一个新的默认ExecutorService
|
// 给所有client给一个新的默认ExecutorService
|
||||||
int clientThreads = executorConf.getIntValue("clients", Utility.cpus() * 4);
|
int clientThreads = executorConf.getIntValue("clients", WorkThread.DEFAULT_WORK_POOL_SIZE);
|
||||||
clientWorkExecutor = WorkThread.createWorkExecutor(clientThreads, "Redkale-DefaultClient-WorkThread-%s");
|
clientWorkExecutor = WorkThread.createWorkExecutor(clientThreads, "Redkale-DefaultClient-WorkThread-%s");
|
||||||
executorLog.append(", threads=").append(clientThreads).append("}");
|
executorLog.append(", threads=").append(clientThreads).append("}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public abstract class Server<
|
|||||||
"UDP".equalsIgnoreCase(netprotocol) ? UDP_BUFFER_CAPACITY : 32 * 1024);
|
"UDP".equalsIgnoreCase(netprotocol) ? UDP_BUFFER_CAPACITY : 32 * 1024);
|
||||||
this.bufferCapacity =
|
this.bufferCapacity =
|
||||||
"UDP".equalsIgnoreCase(netprotocol) ? bufCapacity : (bufCapacity < 1024 ? 1024 : bufCapacity);
|
"UDP".equalsIgnoreCase(netprotocol) ? bufCapacity : (bufCapacity < 1024 ? 1024 : bufCapacity);
|
||||||
this.bufferPoolSize = config.getIntValue("bufferPoolSize", Utility.cpus() * 8);
|
this.bufferPoolSize = config.getIntValue("bufferPoolSize", ByteBufferPool.DEFAULT_BUFFER_POOL_SIZE);
|
||||||
this.responsePoolSize = config.getIntValue("responsePoolSize", 1024);
|
this.responsePoolSize = config.getIntValue("responsePoolSize", 1024);
|
||||||
this.name = config.getValue(
|
this.name = config.getValue(
|
||||||
"name",
|
"name",
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ import org.redkale.util.Utility;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public class WorkThread extends Thread implements Executor {
|
public class WorkThread extends Thread implements Executor {
|
||||||
|
|
||||||
|
public static final int DEFAULT_WORK_POOL_SIZE = Utility.cpus() * 8;
|
||||||
|
|
||||||
protected final ExecutorService workExecutor;
|
protected final ExecutorService workExecutor;
|
||||||
|
|
||||||
// WorkThread下标,从0开始
|
// WorkThread下标,从0开始
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import static org.redkale.boot.Application.RESNAME_APP_NODEID;
|
|||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.mq.spi.MessageAgent;
|
import org.redkale.mq.spi.MessageAgent;
|
||||||
|
import org.redkale.net.WorkThread;
|
||||||
import static org.redkale.net.http.WebSocket.RETCODE_GROUP_EMPTY;
|
import static org.redkale.net.http.WebSocket.RETCODE_GROUP_EMPTY;
|
||||||
import org.redkale.net.sncp.Sncp;
|
import org.redkale.net.sncp.Sncp;
|
||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
@@ -81,7 +82,7 @@ public abstract class WebSocketNode implements Service {
|
|||||||
if (localEngine != null) {
|
if (localEngine != null) {
|
||||||
int wsthreads = localEngine.wsThreads;
|
int wsthreads = localEngine.wsThreads;
|
||||||
if (wsthreads == 0) {
|
if (wsthreads == 0) {
|
||||||
wsthreads = Utility.cpus() * 8;
|
wsthreads = WorkThread.DEFAULT_WORK_POOL_SIZE;
|
||||||
}
|
}
|
||||||
if (wsthreads > 0) {
|
if (wsthreads > 0) {
|
||||||
this.semaphore = new Semaphore(wsthreads);
|
this.semaphore = new Semaphore(wsthreads);
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ import java.util.concurrent.atomic.LongAdder;
|
|||||||
*/
|
*/
|
||||||
public class ByteBufferPool extends ObjectPool<ByteBuffer> {
|
public class ByteBufferPool extends ObjectPool<ByteBuffer> {
|
||||||
|
|
||||||
|
public static final int DEFAULT_BUFFER_POOL_SIZE = Utility.cpus() * 4;
|
||||||
|
|
||||||
|
public static final int DEFAULT_BUFFER_CAPACITY = 16 * 1024;
|
||||||
|
|
||||||
private final int bufferCapacity;
|
private final int bufferCapacity;
|
||||||
|
|
||||||
protected ByteBufferPool(
|
protected ByteBufferPool(
|
||||||
|
|||||||
Reference in New Issue
Block a user