持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第29天,点击查看活动详情
Background
前端页面表单输入数据较多,包含多个文本、多张图片,在数据未压缩的情况下,最终上传失败。
Problem 1
后端报错:
java.lang.IllegalStateException: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector
即:请求数据量过大,超出了最大阈值。
- Solution:
修改Spring Boot
内置Tomcat的maxPostsize
值,在application.yml
配置文件中添加以下内容:
server: tomcat: max-http-post-size: -1
Note: 以下配置并不能解决Tomcat请求数据量的限制问题
spring: servlet: multipart: max-file-size: 30Mb max-request-size: 100Mb
Problem 2
解决了应用服务器请求数据量过大问题后,在下一步写入DB时又遇到了类似问题,超出了数据库中最大允许数据包默认配置值。
Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (16800061 > 16777216). You can change this value on the server by setting the max_allowed_packet' variable.
- Solution:
修改DB的max_allowed_packet
值:
USE demo; set global max_allowed_packet = 3*1024*1024*10; # 改为30M show VARIABLES like '%max_allowed_packet%'; # 重启DB连接生效
Note:MySQL
中max_allowed_packet
的 默认配置:16777216 = 16 * 1024 * 1024
,即16M
Problem3
环境:Linux VM_43_129_centos 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: 0,1 Thread(s) per core: 1 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 63 Model name: Intel(R) Xeon(R) CPU E5-26xx v3 Stepping: 2 CPU MHz: 2294.686 BogoMIPS: 4589.37 Hypervisor vendor: KVM Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 4096K NUMA node0 CPU(s): 0,1
- Tomcat 启动报错,查看日志:
There is insufficient memory for the Java Runtime Environment to continue.
内存不够用了!。?,可是,那可是8个G呀~
free -h
查看内存使用情况:
可用内存仅剩550M!
Analysis
因为服务器上除了Java
环境,MQ
、MySQL
服务外,基本没其他的主要服务了,怀疑是Tomcat
没有关闭导致;
ps -ef |grep tomcat
查看Tomcat相关进程:
可以看到,Tomcat仍有多个进程在运行。
Solution
手动kill对应的pid,再次 free -h
查看内存使用情况:
可用内存瞬间恢复,尝试启动Tomcat,成功~
至于为何Tomcat在shutdown后依然有进程在运行,这个还需进一步探讨。
If you have any questions or any bugs are found, please feel free to contact me.
Your comments and suggestions are welcome!