Redian新闻
>
Servlet的IO吞吐瓶颈在哪里?为什么测下来只有3M bytes 左右?
avatar
Servlet的IO吞吐瓶颈在哪里?为什么测下来只有3M bytes 左右?# Java - 爪哇娇娃
d*r
1
Servlet的IO吞吐瓶颈在哪里?为什么测下来只有3M bytes 左右?
想测一下Tomcat servlet 的输出能力,就写了如下代码段:
1. Server: P4 3.0G, 1G DDR400 memory
输出一个100M bytes的http 文本。servlet key code segment 如下:
avatar
m*t
2

I doubt you can get much faster than that. There's lots of overhead incurred
by the whole stack. A 3.5MBps rate of *payload* transmission implies a much
higher actual transmission rate.
Really? My experience has been the opposite constantly. How did you
benchmark it? Note that by the time you see the "flying files" dialog,
some overhead has already happened, so you can't really get an
accurate benchmark by timing the dialog.
All said and done, I wouldn't worry too much about the 3.5MBps rate -

【在 d********r 的大作中提到】
: Servlet的IO吞吐瓶颈在哪里?为什么测下来只有3M bytes 左右?
: 想测一下Tomcat servlet 的输出能力,就写了如下代码段:
: 1. Server: P4 3.0G, 1G DDR400 memory
: 输出一个100M bytes的http 文本。servlet key code segment 如下:

avatar
d*r
3
有多种办法可以监测网络吞吐:
可以在Windows Task Manager中的Networking中
也可以用DUMeter,
我两者都用了,TCP overhead并不高。
我这两台电脑的硬盘对拷,双方都是SATA RAID0,Gigabit网络连接,
速度至少30MB /s ,GB网卡的利用率峰值可接近30% (300M bps)。
所以TCP overhead并不足以解释何以servlet的吞吐率只有3.5MBytes/s (30M bps),
仅为windows network neighbor 文件copy的 1/10。
不知何故?

【在 m******t 的大作中提到】
:
: I doubt you can get much faster than that. There's lots of overhead incurred
: by the whole stack. A 3.5MBps rate of *payload* transmission implies a much
: higher actual transmission rate.
: Really? My experience has been the opposite constantly. How did you
: benchmark it? Note that by the time you see the "flying files" dialog,
: some overhead has already happened, so you can't really get an
: accurate benchmark by timing the dialog.
: All said and done, I wouldn't worry too much about the 3.5MBps rate -

avatar
m*t
4

I'm a bit confused. In the OP you only mentioned "100M LAN" instead of
Gigabit.
If you are getting this rate over a gigabit connection, I guess
you'd have to blame all the buffer copying inside the java stream
implementation. Did you try to open up a socket yourself and see
how fast that goes?

【在 d********r 的大作中提到】
: 有多种办法可以监测网络吞吐:
: 可以在Windows Task Manager中的Networking中
: 也可以用DUMeter,
: 我两者都用了,TCP overhead并不高。
: 我这两台电脑的硬盘对拷,双方都是SATA RAID0,Gigabit网络连接,
: 速度至少30MB /s ,GB网卡的利用率峰值可接近30% (300M bps)。
: 所以TCP overhead并不足以解释何以servlet的吞吐率只有3.5MBytes/s (30M bps),
: 仅为windows network neighbor 文件copy的 1/10。
: 不知何故?

avatar
p*p
5
Servlet just used ServetSocket's I/O Stream, nothing to do with Container.

【在 m******t 的大作中提到】
:
: I'm a bit confused. In the OP you only mentioned "100M LAN" instead of
: Gigabit.
: If you are getting this rate over a gigabit connection, I guess
: you'd have to blame all the buffer copying inside the java stream
: implementation. Did you try to open up a socket yourself and see
: how fast that goes?

avatar
m*t
6

Hmm, no... servlet implementations (including HttpServletRequest and
HttpServletResponse) are container specific. I agree with you that ideally
when you get the output stream it should be exactly the underlying
socket stream, but there are too many layers in between to be sure
- for example, you never know if any filter suddenly decides to get
cute and wrap the output stream with its own buffered version.

【在 p***p 的大作中提到】
: Servlet just used ServetSocket's I/O Stream, nothing to do with Container.
avatar
d*r
7
我在gigabit网上测过windows文件对拷。知道速度是多少。
现在先在100M网卡上测servlet,如果发现100M NIC是瓶颈,
我就会再在Gigabit LAN上再测一次。
结果发现速度太低,100M上只利用了30%的带宽,就没兴趣再在giga LAN上测了。
因为我没有gigabit switch,平常都是用100M,
如果要测gigabit的话,得用一根网线把两台PC的gigabit网卡直接连起来。
平时都是走100M switch的

【在 m******t 的大作中提到】
:
: Hmm, no... servlet implementations (including HttpServletRequest and
: HttpServletResponse) are container specific. I agree with you that ideally
: when you get the output stream it should be exactly the underlying
: socket stream, but there are too many layers in between to be sure
: - for example, you never know if any filter suddenly decides to get
: cute and wrap the output stream with its own buffered version.

avatar
m*t
8

So you did get 3.5MBps payload transmission rate
over a 100Mbps physical connection, and that's
what I was saying - that's about right,
I don't see anything too far off.

【在 d********r 的大作中提到】
: 我在gigabit网上测过windows文件对拷。知道速度是多少。
: 现在先在100M网卡上测servlet,如果发现100M NIC是瓶颈,
: 我就会再在Gigabit LAN上再测一次。
: 结果发现速度太低,100M上只利用了30%的带宽,就没兴趣再在giga LAN上测了。
: 因为我没有gigabit switch,平常都是用100M,
: 如果要测gigabit的话,得用一根网线把两台PC的gigabit网卡直接连起来。
: 平时都是走100M switch的

avatar
o*g
9
some java code somewhere is to blame (java Socket should be innocent)
to diagnose:
try not use BufferedIn/OutputStream (your buffer is already much bigger
than their buffers)
try run both server and client on localhost
try 2 concurrent clients
try a non java client, say a browser

【在 d********r 的大作中提到】
: Servlet的IO吞吐瓶颈在哪里?为什么测下来只有3M bytes 左右?
: 想测一下Tomcat servlet 的输出能力,就写了如下代码段:
: 1. Server: P4 3.0G, 1G DDR400 memory
: 输出一个100M bytes的http 文本。servlet key code segment 如下:

avatar
d*r
10
试过run server and client @ same PC,差别不大
也试过不用BufferedIn/OutputStream,差别也不大。
没试过2 concurrent clients,回头试试看。

【在 o**g 的大作中提到】
: some java code somewhere is to blame (java Socket should be innocent)
: to diagnose:
: try not use BufferedIn/OutputStream (your buffer is already much bigger
: than their buffers)
: try run both server and client on localhost
: try 2 concurrent clients
: try a non java client, say a browser

avatar
g*g
11
And try nio package see if it helps.

【在 d********r 的大作中提到】
: 试过run server and client @ same PC,差别不大
: 也试过不用BufferedIn/OutputStream,差别也不大。
: 没试过2 concurrent clients,回头试试看。

avatar
y*d
12
你输出 http header 了吗?似乎没有啊,这样 http server 会瞅啊瞅啊瞅不到\r\n\r\n

【在 d********r 的大作中提到】
: Servlet的IO吞吐瓶颈在哪里?为什么测下来只有3M bytes 左右?
: 想测一下Tomcat servlet 的输出能力,就写了如下代码段:
: 1. Server: P4 3.0G, 1G DDR400 memory
: 输出一个100M bytes的http 文本。servlet key code segment 如下:

avatar
d*r
13
这位大侠果然高见,真是一针见血啊。
我在原servlet程序的buffer里,加了一个"\r\n",
结果在Gigabit网上测试,传输率轻松达到了40MB/s,也就是平均约320Mbps,
峰值可达400Mbps。
佩服佩服。
看来现在的瓶颈在系统本身的总线带宽了。

\n

【在 y***d 的大作中提到】
: 你输出 http header 了吗?似乎没有啊,这样 http server 会瞅啊瞅啊瞅不到\r\n\r\n
avatar
y*d
14
哈哈,我牛吧;
注意 header 的结束是“\r\n\r\n”,不是“\r\n”;最好输出完整的 header。

【在 d********r 的大作中提到】
: 这位大侠果然高见,真是一针见血啊。
: 我在原servlet程序的buffer里,加了一个"\r\n",
: 结果在Gigabit网上测试,传输率轻松达到了40MB/s,也就是平均约320Mbps,
: 峰值可达400Mbps。
: 佩服佩服。
: 看来现在的瓶颈在系统本身的总线带宽了。
:
: \n

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。