Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
smthing committed Nov 26, 2024
1 parent 29149b9 commit fd54974
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 42 deletions.
Binary file removed pages/public/pk-smart-servlet.png
Binary file not shown.
Binary file removed pages/public/pk-tomcat.png
Binary file not shown.
Binary file removed pages/public/pk-undertow.png
Binary file not shown.
8 changes: 6 additions & 2 deletions pages/src/content/docs/zh-cn/guides/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar:
order: 1
---
import {Image} from "astro:assets";
import {CardGrid, LinkCard, TabItem, Tabs,FileTree} from '@astrojs/starlight/components';
import {CardGrid, LinkCard, TabItem, Tabs, FileTree, Aside} from '@astrojs/starlight/components';

smart-servlet 是一个基于 Jakarta Servlet 6.1 的轻量级 Servlet 容器,适用于 Java 17+ 环境。
![](/smart-servlet/smart-servlet.svg)
Expand Down Expand Up @@ -102,13 +102,17 @@ smart-servlet 是一个基于 Jakarta Servlet 6.1 的轻量级 Servlet 容器,
## 产品对比

**测试场景:**

以工程中的 springboot-demo 模块为压测用例,压测工具为 wrk,1024个并发持续15秒。

| 产品名称 | smart-servlet | Tomcat | Undertow |
| --- | --- | --- | --- |
| 初始Heap内存 | 12MB | 15MB | 15MB |
|初始Metaspace|29MB|30MB|30MB|
|压测 QPS|16W/s|8W/s|14W/s|
|压测 QPS|18W/s|9W/s|15W/s|
|压测Heap峰值|300MB|550MB|750MB|
|结论|性能高、内存低|性能弱、内存中等|性能高、内存高|

<Aside type="note" title="" >
测试结果中 Tomcat 内存低于 Undertow, 很大一部分原因是 Tomcat 并发量远低于 Undertow,因此其内存需求相当较少。
</Aside>
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ public int getPort() {
return port;
}

public void setPort(int port) {
public ContainerConfig setPort(int port) {
this.port = port;
return this;
}

public String getRootContext() {
Expand All @@ -116,56 +117,63 @@ public int getReadBufferSize() {
return readBufferSize;
}

public void setReadBufferSize(int readBufferSize) {
public ContainerConfig setReadBufferSize(int readBufferSize) {
this.readBufferSize = readBufferSize;
return this;
}

public int getThreadNum() {
return threadNum;
}

public void setThreadNum(int threadNum) {
public ContainerConfig setThreadNum(int threadNum) {
this.threadNum = threadNum;
return this;
}

public boolean isSslEnable() {
return sslEnable;
}

public void setSslEnable(boolean sslEnable) {
public ContainerConfig setSslEnable(boolean sslEnable) {
this.sslEnable = sslEnable;
return this;
}

public String getSslCertType() {
return sslCertType;
}

public void setSslCertType(String sslCertType) {
public ContainerConfig setSslCertType(String sslCertType) {
this.sslCertType = sslCertType;
return this;
}

public int getSslPort() {
return sslPort;
}

public void setSslPort(int sslPort) {
public ContainerConfig setSslPort(int sslPort) {
this.sslPort = sslPort;
return this;
}

public int getSslReadBufferSize() {
return sslReadBufferSize;
}

public void setSslReadBufferSize(int sslReadBufferSize) {
public ContainerConfig setSslReadBufferSize(int sslReadBufferSize) {
this.sslReadBufferSize = sslReadBufferSize;
return this;
}

public int getHttpIdleTimeout() {
return httpIdleTimeout;
}

public void setHttpIdleTimeout(int httpIdleTimeout) {
public ContainerConfig setHttpIdleTimeout(int httpIdleTimeout) {
this.httpIdleTimeout = httpIdleTimeout;
return this;
}

public List<Plugin<Request>> getPlugins() {
Expand All @@ -176,8 +184,9 @@ public String getHost() {
return host;
}

public void setHost(String host) {
public ContainerConfig setHost(String host) {
this.host = host;
return this;
}

public boolean isEnabled() {
Expand All @@ -196,35 +205,40 @@ public boolean isNeedClientAuth() {
return needClientAuth;
}

public void setNeedClientAuth(boolean needClientAuth) {
public ContainerConfig setNeedClientAuth(boolean needClientAuth) {
this.needClientAuth = needClientAuth;
return this;
}

public String getSslKeyStore() {
return sslKeyStore;
}

public void setSslKeyStore(String sslKeyStore) {
public ContainerConfig setSslKeyStore(String sslKeyStore) {
this.sslKeyStore = sslKeyStore;
return this;
}

public String getSslKeyStorePassword() {
return sslKeyStorePassword;
}

public void setSslKeyStorePassword(String sslKeyStorePassword) {
public ContainerConfig setSslKeyStorePassword(String sslKeyStorePassword) {
this.sslKeyStorePassword = sslKeyStorePassword;
return this;
}

public String getSslKeyPassword() {
return sslKeyPassword;
}

public void setSslKeyPassword(String sslKeyPassword) {
public ContainerConfig setSslKeyPassword(String sslKeyPassword) {
this.sslKeyPassword = sslKeyPassword;
return this;
}

public void setEnabled(boolean enabled) {
public ContainerConfig setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}
}
9 changes: 4 additions & 5 deletions springboot-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@
<version>2.4</version><!--最新版本 -->
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-undertow</artifactId>-->
<!-- <version>3.3.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-undertow</artifactId>-->
<!-- </dependency>-->

</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public class SmartEmbeddedContainer implements DeployableContainer<SmartEmbedded
/*
* (non-Javadoc)
*
* @see org.jboss.arquillian.spi.client.container.DeployableContainer#getConfigurationClass()
* @see org.jboss.arquillian.spi.client.container
* .DeployableContainer#getConfigurationClass()
*/
public Class<SmartEmbeddedConfiguration> getConfigurationClass() {
return SmartEmbeddedConfiguration.class;
Expand All @@ -59,7 +60,8 @@ public Class<SmartEmbeddedConfiguration> getConfigurationClass() {
/*
* (non-Javadoc)
*
* @see org.jboss.arquillian.spi.client.container.DeployableContainer#getDefaultProtocol()
* @see org.jboss.arquillian.spi.client.container
* .DeployableContainer#getDefaultProtocol()
*/
public ProtocolDescription getDefaultProtocol() {
// Jetty 9 is a Servlet 3.1 container.
Expand All @@ -84,22 +86,11 @@ public void start() throws LifecycleException {
}

ContainerConfig config = containerRuntime.getConfiguration();
config.setPort(containerConfig.getBindHttpPort());
config.setReadBufferSize(1024 * 1024);
config.setHttpIdleTimeout(120000);
config.setHost(containerConfig.getBindAddress());
config.setPort(containerConfig.getBindHttpPort()).setReadBufferSize(1024 * 1024).setHttpIdleTimeout(120000).setHost(containerConfig.getBindAddress());
config.getPlugins().add(new StreamMonitorPlugin<>(StreamMonitorPlugin.BLUE_TEXT_INPUT_STREAM, StreamMonitorPlugin.RED_TEXT_OUTPUT_STREAM));

if (containerConfig.isSsl()) {
config.setEnabled(false);
config.setSslEnable(true);
config.setNeedClientAuth(containerConfig.isNeedClientAuth());
config.setSslKeyStore(containerConfig.getKeystorePath());
config.setSslKeyStorePassword("changeit");
config.setSslKeyPassword("changeit");
config.setSslCertType("jks");
config.setSslPort(containerConfig.getBindHttpPort());
config.setNeedClientAuth(containerConfig.isNeedClientAuth());
config.setEnabled(false).setSslEnable(true).setNeedClientAuth(containerConfig.isNeedClientAuth()).setSslKeyStore(containerConfig.getKeystorePath()).setSslKeyStorePassword("changeit").setSslKeyPassword("changeit").setSslCertType("jks").setSslPort(containerConfig.getBindHttpPort()).setNeedClientAuth(containerConfig.isNeedClientAuth());
}
listeningHost = containerConfig.getBindAddress();
listeningPort = containerConfig.getBindHttpPort();
Expand All @@ -120,7 +111,9 @@ public void stop() throws LifecycleException {
/*
* (non-Javadoc)
*
* @see org.jboss.arquillian.spi.client.container.DeployableContainer#deploy(org.jboss.shrinkwrap.descriptor.api.Descriptor)
* @see org.jboss.arquillian.spi.client.container
* .DeployableContainer#deploy(org.jboss.shrinkwrap.descriptor.api
* .Descriptor)
*/
public void deploy(Descriptor descriptor) throws DeploymentException {
throw new UnsupportedOperationException("Not implemented");
Expand All @@ -129,24 +122,30 @@ public void deploy(Descriptor descriptor) throws DeploymentException {
/*
* (non-Javadoc)
*
* @see org.jboss.arquillian.spi.client.container.DeployableContainer#undeploy(org.jboss.shrinkwrap.descriptor.api.Descriptor)
* @see org.jboss.arquillian.spi.client.container
* .DeployableContainer#undeploy(org.jboss.shrinkwrap.descriptor.api
* .Descriptor)
*/
public void undeploy(Descriptor descriptor) throws DeploymentException {
throw new UnsupportedOperationException("Not implemented");
}

public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
try {
ServletContextRuntime app = appProvider.createApp(containerRuntime, archive);
ServletContextRuntime app =
appProvider.createApp(containerRuntime, archive);

app.start();

webAppContextProducer.set(app);
servletContextInstanceProducer.set(app.getServletContext());

HTTPContext httpContext = new HTTPContext(listeningHost, listeningPort);
for (ServletInfo servlet : app.getDeploymentInfo().getServlets().values()) {
httpContext.add(new Servlet(servlet.getServletName(), app.getContextPath()));
HTTPContext httpContext = new HTTPContext(listeningHost,
listeningPort);
for (ServletInfo servlet :
app.getDeploymentInfo().getServlets().values()) {
httpContext.add(new Servlet(servlet.getServletName(),
app.getContextPath()));
}
return new ProtocolMetaData().addContext(httpContext);
} catch (Throwable e) {
Expand Down

0 comments on commit fd54974

Please sign in to comment.