Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsp(x) speed bug fix #40

Merged
merged 3 commits into from
May 27, 2021
Merged

jsp(x) speed bug fix #40

merged 3 commits into from
May 27, 2021

Conversation

XinRoom
Copy link
Contributor

@XinRoom XinRoom commented May 26, 2021

buf.clear(); 会重置缓冲区的主要索引值,不必为了每次读写都创建新的缓冲区;如果在下次写入之前不这么做,那么下次写入总是失败的。这将导致while循环总是只执行一次,每次http链接只能传输513字节长度的数据,降低效率。

以下是测试数据:
未添加buf.clear();时:
1

让我们看看while循环执行的情况:
2
显然,第二次写buf总是失败,长度为0,导致while循环只能执行1次。数据将会被分成多次http连接传递,降低传输效率。

添加buf.clear();时:
3

单次可传递数据明显变多:
4

curl 传输速度对比:
image

`buf.clear();` 会重置缓冲区的主要索引值,不必为了每次读写都创建新的缓冲区;如果在下次写入之前不这么做,那么下次写入总是失败的。这将导致while循环总是只执行一次,数据只能513字节长度的传输,降低效率。
@L-codes
Copy link
Owner

L-codes commented May 27, 2021

感谢提交,这是前不久版本删除的代码clear() 原因是部分环境报错,感谢提醒性能bug存在,但估计得用其它办法解决比如创建多个buf

@XinRoom
Copy link
Contributor Author

XinRoom commented May 27, 2021

感谢提交,这是前不久版本删除的代码clear() 原因是部分环境报错,感谢提醒性能bug存在,但估计得用其它办法解决比如创建多个buf

我测试了asuuto/tomcat6-jdk6(Apache Tomcat/6.0.53+jdk6)、apsl/tomcat5(Apache Tomcat/5.5.36+jdk1.5.0_22)没有发现问题
可否告知下是什么版本的环境?

@XinRoom
Copy link
Contributor Author

XinRoom commented May 27, 2021

查阅了下互联网资料,似乎问题会出在使用jdk9编译,并在jdk8上运行是会出现java.lang.NoSuchMethodError问题:
plasma-umass/doppio#497 (comment)

可以使用强制类型转换解决:
((java.nio.Buffer)buf).clear();

修复当使用jdk9编译的class运行于jdk8时buf.clear()错误的问题  plasma-umass/doppio#497
见jsp speed bug fix: L-codes#40
@XinRoom XinRoom changed the title jsp speed bug fix jsp(s) speed bug fix May 27, 2021
@XinRoom XinRoom changed the title jsp(s) speed bug fix jsp(x) speed bug fix May 27, 2021
@L-codes
Copy link
Owner

L-codes commented May 27, 2021

((java.nio.Buffer)buf).clear(); 这个可以晚点我测试一下,可以的话我合并一下RP;不知道 out.flush() 是否也会存在同样问题?

@XinRoom
Copy link
Contributor Author

XinRoom commented May 27, 2021

((java.nio.Buffer)buf).clear(); 这个可以晚点我测试一下,可以的话我合并一下RP;不知道 out.flush() 是否也会存在同样问题?

out.flush() 应该没有兼容问题,out.flush() 在小数据传输的时候会更具有实时性。目前来看对性能影响不大。

可以再充分测试一下。

@L-codes L-codes merged commit 33fc1c6 into L-codes:master May 27, 2021
@L-codes
Copy link
Owner

L-codes commented May 27, 2021

再次感谢 RP 提交,测试没有问题!并发布了 v3.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants