简体   繁体   English

使用Java客户端的Java OutputStream文件上传性能

[英]Java OutputStream file upload performances using httpclient

I have a java jar application running in the background of my linux servers (debian 7). 我在Linux服务器(debian 7)的后台运行了一个Java jar应用程序。 The servers receives files through apache generally, then the jar pull the database regularly to upload the files to their final destination using a pool of http connections from an httpclient (v2.5). 服务器通常通过apache接收文件,然后jar定期使用来自httpclient(v2.5)的http连接池将数据库拉入数据库,以将文件上传到最终目的地。

The servers are 16gb of ram, 8 cores cpu, 1To disk and 2Gb/s internet bandwidth. 服务器的内存为16gb的ram,8核cpu,1To磁盘和2Gb / s的互联网带宽。 My problem is that the bandwidth is only used at 10% or 20% for the uploads made by the jar. 我的问题是,jar的上传仅使用10%或20%的带宽。 After many investigations I think it is because of the capacity of the distant server which might be the bottleneck. 经过大量调查,我认为这是因为远程服务器的容量可能成为瓶颈。 So I wanted to launch more threads on my servers to proceed more files at the same time and use all the bandwidth I have, unfortunately file upload with httpclient is eating a lot of cpu it seems ! 因此,我想在服务器上启动更多线程以同时处理更多文件并使用我拥有的所有带宽,不幸的是,使用httpclient上传文件似乎占用了很多CPU!

Actually the jars are working with 20 simultaneous upload runnable threads and the cpu is constantly at 100%, if I try to start more threads the load average increase and break records, getting the system so slow and unusable. 实际上,jar可以同时处理20个可上传的可运行线程,而CPU始终保持100%的速度,如果我尝试启动更多线程,则平均负载会增加并打破记录,从而使系统变得如此缓慢且无法使用。 Strange thing is the iowaits seems to be null, so I really don't know what is causing the load average. 奇怪的是iowaits似乎为空,所以我真的不知道是什么导致平均负载。

I have run an hprof using only one thread, here is the result : 我只使用一个线程运行了一个hprof,结果如下:

CPU SAMPLES BEGIN (total = 4617) Thu Jul 28 17:42:35 2016 rank self accum count trace method 1 52.76% 52.76% 2436 301157 java.net.SocketOutputStream.socketWrite0 2 33.53% 86.29% 1548 300806 java.net.SocketInputStream.socketRead0 3 1.62% 87.91% 75 301138 org.sqlite.core.NativeDB.step 4 1.47% 89.39% 68 301158 java.io.FileInputStream.readBytes 5 1.06% 90.45% 49 300078 java.lang.ClassLoader.defineClass1 6 0.26% 90.71% 12 300781 com.mysql.jdbc.SingleByteCharsetConverter.<clinit> 7 0.19% 90.90% 9 300386 java.lang.Throwable.fillInStackTrace 8 0.19% 91.10% 9 300653 java.lang.ClassLoader.loadClass 9 0.19% 91.29% 9 300780 com.mysql.jdbc.SingleByteCharsetConverter.<clinit> 10 0.17% 91.47% 8 300387 java.net.URLClassLoader.findClass 11 0.17% 91.64% 8 300389 java.util.zip.Inflater.inflateBytes 12 0.15% 91.79% 7 300090 java.lang.ClassLoader.findBootstrapClass 13 0.15% 91.94% 7 300390 java.util.zip.ZipFile.getEntry 14 0.13% 92.07% 6 300805 java.net.PlainSocketImpl.socketConnect

the files are sent with a common httpclient POST execute request with an overrided writeTo() method from the filebody class that uses a bufferedInputStream of 8kb. 这些文件是通过使用8kb的bufferedInputStream的filebody类中的公共httpclient POST执行请求和重写的writeTo()方法发送的。

Do you think it is possible to reduce the performance impact of the file uploads, and solve my problem of unused bandwidth ? 您是否认为可以减少文件上传的性能影响,并解决我的未使用带宽问题?

Thanks in advance for your help. 在此先感谢您的帮助。

You should try https://hc.apache.org/ 您应该尝试https://hc.apache.org/

You could change your httpclient library to an library based on java.nio: https://docs.oracle.com/javase/7/docs/api/java/nio/package-summary.html 您可以将httpclient库更改为基于java.nio的库: https : //docs.oracle.com/javase/7/docs/api/java/nio/package-summary.html

HttpCore is a set of low level HTTP transport components that can be used to build custom client and server side HTTP services with a minimal footprint. HttpCore是一组低级HTTP传输组件,可用于以最小的占用空间构建自定义客户端和服务器端HTTP服务。 HttpCore supports two I/O models: blocking I/O model based on the classic Java I/O and non-blocking, event driven I/O model based on Java NIO . HttpCore支持两种I / O模型:基于经典Java I / O的阻塞I / O模型和基于Java NIO的非阻塞事件驱动的I / O模型。

Please take a look at https://hc.apache.org/httpcomponents-asyncclient-dev/index.html 请查看https://hc.apache.org/httpcomponents-asyncclient-dev/index.html

Hope this is the right idea. 希望这是正确的想法。

In fact it appears that the problem was not coming from the java process but from apache consuming all the IO of the hard drive, screwing up the performances. 实际上,问题似乎不是来自Java进程,而是由于Apache消耗了硬盘驱动器的所有IO,从而破坏了性能。 Thanks for your help anyway. 还是要谢谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM