上傳大文件經過zuul網關,包head space內存溢出
處理方式有兩種
1.在application.yml配置中增加file-size-threshold: 20MB
spring: application: name: zuul-gateway servlet: #spring boot2.0之前是http multipart: enabled: true # 使用http multipart上傳處理 max-file-size: 1000MB # 設置單個文件的最大長度,默認1M,如不限制配置爲-1 max-request-size: 1000MB # 設置最大的請求文件的大小,默認10M,如不限制配置爲-1 file-size-threshold: 100MB # 當上傳文件達到100MB的時候進行磁盤寫入 location: / # 上傳的臨時目錄
2.修改配置,讓網關只做簡單處理後就直接交給服務的上傳接口處理
對於大文件,可以繞過Spring DispatcherServlet(以避免多部分處理)在“/zuul/”中。換句話說,如果你有zuul.route.customers=/customers/*,然後您可以將大文件發佈到/zuul/customers/*。servlet路徑通過zuul.servletPath外部化。
注意:大文件需要修改超時機制
hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 160000 ribbon: ReadTimeout: 300000 ConnectTimeout: 300000 MaxAutoRetries: 1 MaxAutoRetriesNextServer: 1