Tomcat最大并发文件上传数

发布于 2024-10-07 09:26:52 字数 911 浏览 1 评论 0原文

我有一个具有 250 个连接线程的 Tomcat 服务器。当我模拟 30 个文件(每个 100 MB)的并发文件上传时,服务器计算机的 CPU 和 RAM 内存达到峰值,即 95% 使用率。

我使用以下代码块从 HTTP Post 读取文件数据。

// request is instance of HTTPServletRequest
int nDataLength = request.getContentLength();

byte dataBytes[] = new byte[nDataLength];

int bytesRead = 0;
int totalBytesRead = 0;
int bytesLimit = 1024;

InputStream in = new InputStream(request.getInputStream());
try
{
    while(totalBytesRead < nDataLength)
    {
        bytesRead = in.read(dataBytes, totalBytesRead, bytesLimit);
        totalBytesRead  += bytesRead;
    }
}
catch(Exception ex)
{
    throw ex;
}
finally
{
    in.close();
}

我的疑问是:

  • Tomcat 服务器可以处理的最大并发文件上传数量(每个 100 MB 文件)是多少?
  • 我的代码是否需要进行任何优化才能利用所有 250 个连接线程?
  • 引入 sleep 可能会导致上传时间过长。如何写出高效的代码?

提前致谢。

问候, Kingsley Reuben J

注意:我无法使用第三方应用程序来解决此问题

I have a Tomcat Server with 250 connection threads. When I simulate concurrent file upload for 30 files (each 100 MB), the CPU and RAM Memory of the server machine goes to peak i.e., 95% usage.

I use following block of code to read the file data from HTTP Post.

// request is instance of HTTPServletRequest
int nDataLength = request.getContentLength();

byte dataBytes[] = new byte[nDataLength];

int bytesRead = 0;
int totalBytesRead = 0;
int bytesLimit = 1024;

InputStream in = new InputStream(request.getInputStream());
try
{
    while(totalBytesRead < nDataLength)
    {
        bytesRead = in.read(dataBytes, totalBytesRead, bytesLimit);
        totalBytesRead  += bytesRead;
    }
}
catch(Exception ex)
{
    throw ex;
}
finally
{
    in.close();
}

My doubts are:

  • What could be the maximum number of concurrent File Uploads (each 100 MB files) that a Tomcat Server can handle ?
  • Is there any optimization required in my code to make use of all 250 connection threads ?
  • Introducing sleep can cause lengthy uploads. How to write efficient code ?

Thanks in advance.

regards,
Kingsley Reuben J

NOTE: I wont be able to use third party applications to resolve this problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔落惊风雨 2024-10-14 09:26:52

原始解决方案的内存不足,因此 stacker 的建议(将数据存储在文件中)应该可行。通过 http 将文件上传到 tomcat 对于批量上传来说并不理想。

您可以尝试使用更简单的服务器/更高效的协议(例如 ftp)或分析您的应用程序服务器和应用程序。应用程序来查看您的瓶颈在哪里。我想到的一件事是 HTTP 上传必须进行 MIME 解码。

You're running out of memory with the original solution, so stacker's suggestion (storing data in file) should work. Uploading files over http to tomcat is just not ideal to do bulk massive uploads.

You could try using a simpler server / more efficient protocol (e.g. ftp) or profile your Application Server & Application to see where your bottleneck is. One of the things that comes to mind is that HTTP uploads have to be MIME-decoded.

固执像三岁 2024-10-14 09:26:52

您应该将接收到的数据写入临时文件(以较小的块,例如 8KB),因为 30 * 100MB = 3GB,并且您的机器可能开始调出内存。吞吐量受到接口适配器的限制。

You should write the received data to a temporary file (in smaller blocks, say 8KB) since 30 * 100MB = 3GB and probably you machine starts paging out memory. The throughput is limited by you interface adapter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文