Reliable data serving

送分小仙女□ 提交于 2019-11-26 06:49:06

问题


How can i make sure my file serving is reliable and scalable? How many parallel request it can handle?

I am thinking beyond the hardware capability and band width.

i am following Streaming large files in a java servlet


回答1:


If those are static files, just link to it directly. All decent servletcontainers/appservers have a well-developed DefaultServlet. If those are static files located outside the webapplication from where you'd link them to, then you can also just add the root folder of those files as another context. It's unclear which server you're using, but if it were Tomcat, you could just add a new <Context> to server.xml:

<Context docBase="/path/to/static/files" path="/files" />

This way it's accessible by http://example.com/files/....

If those are dynamically generated files or files coming from a database, then you need to develop a servlet which does the IO job efficiently: i.e. do not unnecessarily store the entire data in memory (e.g. in a ByteArrayInputStream or byte[] before emitting them to the output. Just write the bytes immediately to the output as it comes in. You may find this those examples of a basic fileservlet and a more advanced fileservlet (supporting resumes and so on) useful.




回答2:


If you are just serving static files from a file system just use Apache - it's going to be better then anything you will write yourself.



来源:https://stackoverflow.com/questions/1502841/reliable-data-serving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!