简体   繁体   English

如何在spring-mvc和tomcat中改善静态资源的流

[英]How to improve the streaming of static resources in spring-mvc and tomcat

I am building an application that plays opus audio files stored on a nas mounted on the application server. 我正在构建一个播放存储在安装在应用程序服务器上的nas上的opus音频文件的应用程序。 The application reads these files, and send them to the HTTP response output stream. 应用程序读取这些文件,并将它们发送到HTTP响应输出流。

I am using spring-mvc and the web application runs on tomcat. 我正在使用spring-mvc,并且Web应用程序在tomcat上运行。 I get the audio files using: 我使用以下方法获取音频文件:

<mvc:resources mapping="/audios/**" location="file:/path/to/the/mounted/nas"/>

and I serve them in a <audio> tag. 然后将它们放在<audio>标签中。

Now I would like to make the application extremely reactive and multi user friendly. 现在,我想使该应用程序具有极好的反应性和多用户友好性。 If I have 20 people playing many audio simultaneously, the system gets very slow and I do not know what is the best thing to do. 如果我有20个人同时播放许多音频,则系统会变得非常缓慢,并且我不知道最好的方法是什么。

Could you please suggest me how to improve the application 您能否建议我如何改善应用程序

Thanks 谢谢

You have to first investigate where is the actual delay happening. 您必须首先调查实际延迟发生在哪里。 Is it in getting resource from file system from within the code, or it is because Tomcat is not able to withstand more load. 是从代码中从文件系统获取资源,还是因为Tomcat无法承受更多的负载。 To make sure it's not the code issue, you can log the code execution time and check if everything is fine there. 为了确保这不是代码问题,您可以记录代码执行时间,并检查是否一切正常。 Here is the way to do that - How do I time a method's execution in Java? 这是执行此操作的方法- 如何在Java中计时方法的执行时间?

Now if it's the Tomcat server which is not able to withstand the load, which looks more probable issue, you might want to consider having cluster of multiple tomcat instances by creating a load balancer configuration with Apache web server. 现在,如果看起来是可能无法承受负载的是Tomcat服务器,那么您可能希望通过使用Apache Web服务器创建负载平衡器配置来考虑具有多个tomcat实例的集群。 This way requests traffic load will be distributed by web server to all the running tomcat nodes, which will reduce the latency. 这样,Web服务器将请求流量负载分配给所有正在运行的tomcat节点,这将减少延迟。

You can find how to configure load balancing at these link- 您可以在以下链接找到如何配置负载平衡-

http://www.tutorialspoint.com/white-papers/load-balancing-and-scalability-via-tomcat-clusters.htm http://www.tutorialspoint.com/white-papers/load-balancing-and-scalability-via-tomcat-clusters.htm

https://tomcat.apache.org/connectors-doc/generic_howto/loadbalancers.html https://tomcat.apache.org/connectors-doc/generic_howto/loadbalancers.html

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

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