服务器情况:
一台前端服务器(Nginx)做反向代理
二台后端下载服务器(Tomcat)
public void download(@PathVariable("id") String id, HttpServletResponse response) {
try {
APackage aPackage = packageService.findPackageById(id);
String path = PathManager.getFullPath(aPackage) + aPackage.getFileName();
File file = new File(path);
if (file.exists()) { //判断文件父目录是否存在
response.setContentType("application/force-download");
// 文件名称转换
String fileName = aPackage.getName() + "_" + aPackage.getVersion();
String ext = "." + FilenameUtils.getExtension(aPackage.getFileName());
String appName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
response.setHeader("Content-Disposition", "attachment;fileName=" + appName + ext);
byte[] buffer = new byte[1024];
OutputStream os = response.getOutputStream();
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer);
i = bis.read(buffer);
}
bis.close();
fis.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
<!-- 配置tomcatPool-->
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="800" minSpareThreads="100" maxQueueSize="100" prestartminSpareThreads="true"/>
<!-- 启动NIO 来提升Tomcat性能 -->
<Connector executor="tomcatThreadPool" port="****" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="****"
enableLookups="false"
maxPostSize="10485760"
URIEncoding="UTF-8"
acceptCount="100"
acceptorThreadCount="2"
disableUploadTimeout="true"
maxConnections="10000"
SSLEnabled="false" />
我尝试配置了中间件Tomcat的配置,调整为NIO模式。
希望大家指点,如何跟踪排查问题,代码上是否能提供优化方案。
带宽满了你优化后台有什么用
50KB已经很不错了,说明只有100个人在同时下载
如果有10000个人在同时下载,每个人的带宽就只剩500B了
缺硬件就加硬件,不要老想搞软件
只能给点思路 不一定是正确的 因为下载东西的这种软件我们公司也做过 上次客户那边反馈也是下载慢 然后我们运维排查 说是网关跑满了 不知道能不能给你提供一点帮助