Skip to content

Slow webflux multipart upload #34651

Closed as not planned
Closed as not planned

Description

@sbxz

Hello,

We are developing a document submission application using WebFlux. However, we have noticed that handling multipart requests is slower with WebFlux compared to MVC. For example, when using MultipartFile in MVC, sending a 200MB file takes about 700ms, whereas it takes 4.2s with WebFlux (FilePart) and 4.5s with PartEvent.

Did we miss something?

Here is a repository reproducing the issue: Repo

Spring boot version : 3.4.4
Java 21

Activity

  1. self-assigned this
    on Mar 26, 2025
  2. added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    and removed on Mar 26, 2025
  3. added this to the 6.2.x milestone on Mar 26, 2025
  4. sdeleuze commented on Mar 26, 2025

    @sdeleuze
    Contributor

    I suspected that when working in this area recently in #34178 and #34388 but was not 100% sure, but your report seems to confirm there is something to improve there, so I will try to have a deeper look.

    What I saw was slow upload locally with big files, so I know how to reproduce even if for now, I am not sure about the reason.

  5. xyraclius commented on Aug 20, 2025

    @xyraclius
    Contributor

    Hello @sdeleuze

    I’d like to contribute to this, may I ?

    I've reduced the elapsed time from 4.2s to 700ms locally

    Before:

    ~/IdeaProjects/WebfluxSlowMultipart git:[main]
    curl -w "\nElapsed: %{time_total}s\n" \
         -F file="@200mb.pdf" \
         http://localhost:8080/part-event \
         -o /dev/null -s
    Elapsed: 4.260208s
    
    
    ~/IdeaProjects/WebfluxSlowMultipart git:[main]
    curl -w "\nElapsed: %{time_total}s\n" \
      -F file="@200mb.pdf" \
      http://localhost:8080/file-part \
      -o /dev/null -s
      Elapsed: 4.346252s

    After:

    ~/IdeaProjects/WebfluxSlowMultipart git:[main]
    curl -w "\nElapsed: %{time_total}s\n" \
         -F file="@200mb.pdf" \
         http://localhost:8080/part-event \
         -o /dev/null -s
    Elapsed: 0.391556s
    
    
    ~/IdeaProjects/WebfluxSlowMultipart git:[main]
    curl -w "\nElapsed: %{time_total}s\n" \
      -F file="@200mb.pdf" \
      http://localhost:8080/file-part \
      -o /dev/null -s
    Elapsed: 0.407896s
    
    
  6. bclozel commented on Aug 21, 2025

    @bclozel
    Member

    @xyraclius please share your findings, it is hard for us to tell you whether a contribution would be accepted if we don't know the type of changes you are working on.

  7. assigned and unassigned on Oct 10, 2025
  8. bclozel commented on Oct 13, 2025

    @bclozel
    Member

    A quick profiling session shows that NettyDataBuffer.getByte() is responsible here for most of the overhead. This is quite similar to an issue reported to Netty.

    Image

    I think we should introduce an efficient variant in DataBuffer for traversing bytes from a DataBuffer, I have created #35623 for that. This is generally useful and in my tests this brings a x2 improvement. We would still need another x2 improvement to be on par with the multipart support from Servlet containers, but this is a good first step.

  9. modified the milestones: 6.2.x, 7.0.x on Nov 27, 2025
  10. bclozel commented on Apr 2, 2026

    @bclozel
    Member

    I'm not seeing obvious large contributors when profiling multipart uploads. I'll close this issue for now but we can reopen if we get a flame chart that points to something we can optimize.

  11. removed this from the 7.0.x milestone on Apr 2, 2026
  12. removed their assignment
    on Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions