WEB开发中。下载服务器上面的报表。怎么防止数据量过大导致超时的场景
问题
需要服务端生成报表,由于数据量过大。往往会导致下载过程中504错误。
下载流程已经最优化了。
目前解决方案
前台点击下载报表,发起一个异步请求。后台处理完数据以后。把数据通过邮箱的方式发给下载者。
有没有其它更加好的办法,可以解决这个问题?谢谢。
回复内容:
问题
需要服务端生成报表,由于数据量过大。往往会导致下载过程中504错误。
下载流程已经最优化了。
目前解决方案
前台点击下载报表,发起一个异步请求。后台处理完数据以后。把数据通过邮箱的方式发给下载者。
有没有其它更加好的办法,可以解决这个问题?谢谢。
谢谢各位的回答。
这边我自己总结了一下,根据我自己的实际情况主要
- 前台异步提交一个请求,后台进行异步组合报表。然后通过1. 邮件的方式通知用户2. 通过定时器将消息PUSH给用户,让用户去相应的地址上下载
- 查询时间精确到秒。在用户请求之前,先告诉用户在这个时间段订单个数。我们可以设定一个合理的值来提示用户(改动最小)
- 采取任务的形式,前台提交一个任务给后台,后台创建一个任务,并且存入数据库。前台可以每隔30s向后台请求,获取任务的状态,以防止超时。相应的前台有一个loading框(这里也可以改成将文件的生成过程放在服务端,然后这里给用户返回的是一个连接,用户可以直接点连接来下载文件)(这个类似使用AJAX的长连接模式)
- 把分析过程放在服务端。服务端起一个定时任务,隔段时间去分析这些数据。直接生产文件放在服务端。可以提供给用户一个下载列表直接提供给用户下载
5.优化流程,采取dubbo批量数据请求。采取dubbo异步请求。多线程处理数据。多个dubbo服务合并(性能优化)
最直接的办法便是,压缩数据(例如导出时进行压缩),调整 CGI 超时时间。这其中,可以考虑节省 CGI 进程(因为即使输出成果已经完成,按照题主的说明,fast_cgi 的 response buffer 肯定是远远小于这次输出的大小),在最后输出的过程上用其他服务(例如直接用nginx)代劳。
其实,例如在问题中的这种从产品设计的角度解决问题在我看来最优解,实时下载真的是那么必要吗?
需要服务端生成报表,由于数据量过大。往往会导致下载过程中504错误。
看你的意思,超时的原因不是产生报表耗时太久,而是因为报表文件过大造成的。
3种做法
1.压缩报表文件,例如:tar,gzip,zip……
2.修改web服务器的超时时间设定。
3.导出的文件放到另外一个目录用其他工具下载,例如:ftp,samba,sftp……
边读数据,边写数据,比如分页读写,这样就不会超时了
换个思路,你的所有问题都在超时上面! 为什么超时,因为等待时间过长。那为什么要等待呢???
你可以发出请求,服务器端执行,告诉用户,正在执行,表示就成功了。然后就是用户接受邮件的等待。
这个时候,你可以告诉用户需要等待,或者加一个消息通知,成功后通知用户

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.
