|
@@ -12,16 +12,11 @@ import com.zaxxer.hikari.HikariConfig;
|
|
|
import com.zaxxer.hikari.HikariDataSource;
|
|
|
import org.smartboot.Message;
|
|
|
import org.smartboot.aio.EnhanceAsynchronousChannelProvider;
|
|
|
-import org.smartboot.http.server.HttpMessageProcessor;
|
|
|
-import org.smartboot.http.server.HttpRequestProtocol;
|
|
|
import org.smartboot.http.server.Request;
|
|
|
import org.smartboot.http.server.handle.HttpHandle;
|
|
|
import org.smartboot.http.server.handle.HttpRouteHandle;
|
|
|
import org.smartboot.socket.StateMachineEnum;
|
|
|
-import org.smartboot.socket.buffer.BufferFactory;
|
|
|
-import org.smartboot.socket.buffer.BufferPagePool;
|
|
|
import org.smartboot.socket.extension.processor.AbstractMessageProcessor;
|
|
|
-import org.smartboot.socket.transport.AioQuickServer;
|
|
|
import org.smartboot.socket.transport.AioSession;
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
@@ -55,45 +50,25 @@ public class Bootstrap {
|
|
|
}
|
|
|
});
|
|
|
initDB(routeHandle);
|
|
|
- HttpMessageProcessor processor = new HttpMessageProcessor();
|
|
|
- processor.pipeline(routeHandle);
|
|
|
- http(processor);
|
|
|
- }
|
|
|
-
|
|
|
- public static void http(final HttpMessageProcessor processor) {
|
|
|
- AbstractMessageProcessor<Request> messageProcessor = new AbstractMessageProcessor<Request>() {
|
|
|
- @Override
|
|
|
- public void process0(AioSession session, Request msg) {
|
|
|
- processor.process(session, msg);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) {
|
|
|
- processor.stateEvent(session, stateMachineEnum, throwable);
|
|
|
- }
|
|
|
- };
|
|
|
-// messageProcessor.addPlugin(new MonitorPlugin(5));
|
|
|
-// messageProcessor.addPlugin(new SocketOptionPlugin());
|
|
|
-
|
|
|
int cpuNum = Runtime.getRuntime().availableProcessors();
|
|
|
// 定义服务器接受的消息类型以及各类消息对应的处理器
|
|
|
- AioQuickServer<Request> server = new AioQuickServer<>(8080, new HttpRequestProtocol(), messageProcessor);
|
|
|
- server.setThreadNum(cpuNum + 2)
|
|
|
+ HttpBootstrap bootstrap = new HttpBootstrap();
|
|
|
+ bootstrap.setPort(8080).setThreadNum(cpuNum + 2)
|
|
|
.setReadBufferSize(1024 * 4)
|
|
|
- .setBufferFactory(new BufferFactory() {
|
|
|
+ .setReadPageSize(16384 * 1024 * 4)
|
|
|
+ .setBufferPool(10 * 1024 * 1024, cpuNum + 2, 1024 * 4)
|
|
|
+ .pipeline(routeHandle)
|
|
|
+ .wrapProcessor(processor -> new AbstractMessageProcessor<>() {
|
|
|
@Override
|
|
|
- public BufferPagePool create() {
|
|
|
- return new BufferPagePool(10 * 1024 * 1024, cpuNum + 2, 64 * 1024 * 1024, true);
|
|
|
+ public void process0(AioSession session, Request msg) {
|
|
|
+ processor.process(session, msg);
|
|
|
}
|
|
|
- })
|
|
|
- .setWriteBuffer(1024 * 4, 8);
|
|
|
|
|
|
-// messageProcessor.addPlugin(new BufferPageMonitorPlugin(server, 6));
|
|
|
- try {
|
|
|
- server.start();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void stateEvent0(AioSession session, StateMachineEnum stateMachineEnum, Throwable throwable) {
|
|
|
+ processor.stateEvent(session, stateMachineEnum, throwable);
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
}
|
|
|
|
|
|
private static void initDB(HttpRouteHandle routeHandle) {
|
|
@@ -107,9 +82,13 @@ public class Bootstrap {
|
|
|
config.setUsername("benchmarkdbuser");
|
|
|
config.setPassword("benchmarkdbpass");
|
|
|
config.setMaximumPoolSize(64);
|
|
|
+ config.addDataSourceProperty("cachePrepStmts", "true");
|
|
|
+ config.addDataSourceProperty("prepStmtCacheSize", "250");
|
|
|
+ config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
|
|
DataSource dataSource = new HikariDataSource(config);
|
|
|
routeHandle.route("/db", new SingleQueryHandler(dataSource))
|
|
|
.route("/queries", new MultipleQueriesHandler(dataSource))
|
|
|
.route("/updates", new UpdateHandler(dataSource));
|
|
|
+// .route("/fortunes", new FortunesHandler(dataSource));
|
|
|
}
|
|
|
}
|