我们正在维护一个用c#编写的较旧的应用程序,该应用程序将文件(二进制)发送到在tomcat 8下运行的webdaV。我对webdaV的了解很少。基本上,c#客户端正在执行以下操作:
// Create PUT request
HttpWebRequest request = job.Context.HttpUtil.CreateWebRequest(WebRequestMethods.Http.Put,job.Context.Server,job.Resource.ServerPath);
// ...do some stuff to get the stream to send
// Now stream the data to the request
sourceStream.Position = 0;
request.ContentLength = sourceStream.Length;
if (Deserializetask.IsSerializedData(sourceStream))
{
request.ContentType = "application/octet-stream";
}
else
{
request.ContentType = "text/plain";
}
Stream stream = request.GetRequestStream();
byte[] buffer = new byte[0x1000];
int bytes;
while ((bytes = sourceStream.Read(buffer,buffer.Length)) > 0)
{
stream.Write(buffer,bytes);
}
stream.Flush();
stream.Close();
Httpwebresponse response = null;
try
{
response = (Httpwebresponse)request.GetResponse();
job.Context.HttpUtil.LogResponse(response);
}
finally
{
response.Close();
}
这很好。但是,在一些用例中,许多用户可以同时上传非常大的文件,并且我们会从tomcat中引发OOM错误。增加jvm堆不是一种选择。我怀疑webdaV正在等待请求输入流完成并在内存中缓存字节,然后再写入输出流(文件),从而耗尽堆空间。当文件很大时,这将是一个问题。
我的问题是是否有一种方法告诉webdaV(通过webdaV的web.xml servlet设置,某些请求属性等)不缓存输入流中的字节,而是以每1K的速度写入输出缓冲区的数据到达。我研究了webdaV设置和http请求设置,但看不到看起来可以完成此操作的任何内容。还是我们自己编写一个servlet来做到这一点?
发生OOM时从catalina.out中获取:
554080 Exception in thread "http-bio-8080-exec-462" Exception in thread "http-bio-8080-exec-350" at orgapachenamingresourcesProxyDirContextProxyDirContext.java1458)
554081 Exception in thread "http-bio-8080-exec-387" Exception in thread "http-bio-8080-exec-468" Exception in thread "http-bio-8080-exec-375" Exception in thread "http-bio-8080-acceptor-0" Exception in thread "http-bio-8080-exec-364" in thread "http-bio-8080-exec-255" Exception in thread "http-bio-8080-exec-341" at orgapacheservletsDefaultServletDefaultServlet.java762)
554082 at orgapacheservletsDefaultServletDefaultServlet.java409)
554083 at servlethttpHttpServletserviceHttpServlet.java620)
554084 at orgapacheservletsWebdavServletserviceWebdavServlet.java378)
554085 at servlethttpHttpServletserviceHttpServlet.java727)
554086 at orgapachecoreApplicationFilterChainApplicationFilterChain.java303)
554087 at orgapachecoreApplicationFilterChainApplicationFilterChain.java208)
554088 at orgapachetomcatserverWsFilterWsFilter.java52)
554089 at orgapachecoreApplicationFilterChainApplicationFilterChain.java241)
554090 at orgapachecoreApplicationFilterChainApplicationFilterChain.java208)
554091 at orgapachecoreStandardWrapperValveStandardWrapperValve.java220)
554092 at orgapachecoreStandardContextValveStandardContextValve.java122)
554093 at orgapacheauthenticatorauthenticatorBaseAuthenticatorBase.java501)
554094 at orgapachecoreStandardHostValveStandardHostValve.java170)
554095 at orgapachevalvesErrorReportValveErrorReportValve.java98)
554096 at orgapachevalvesaccessLogValveaccessLogValve.java950)
554097 at orgapachecoreStandardEngineValveStandardEngineValve.java116)
554098 at orgapacheconnectorserviceCoyoteAdapter.java408)
554099 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
554100 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
554101 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
554102 at concurrentThreadPoolExecutorThreadPoolExecutor.java1145)
554103 at concurrentThreadPoolExecutor$WorkerThreadPoolExecutor.java615)
554104 at ThreadrunThread.java745)
554105 OutOfMemoryError: Java heap space
554106 OutOfMemoryError: Java heap space
554107 OutOfMemoryError: Java heap space
554108 OutOfMemoryError: Java heap space
554109 OutOfMemoryError: Java heap space
554110 OutOfMemoryError: Java heap space
554111 OutOfMemoryError: Java heap space
554112 OutOfMemoryError: Java heap space
感谢您的任何建议。 -帕特