Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS Streams loads the response in memory instead of streaming #11814

Open
mohittt8 opened this issue May 19, 2023 · 4 comments
Open

WS Streams loads the response in memory instead of streaming #11814

mohittt8 opened this issue May 19, 2023 · 4 comments

Comments

@mohittt8
Copy link

Play Version

2.8.19

API

WS.stream() ( https://www.playframework.com/documentation/2.8.x/ScalaWS#Processing-large-responses )

Scala

Operating System

Mac OS

JDK

openjdk version "11.0.18" 2023-01-17 LTS
OpenJDK Runtime Environment Corretto-11.0.18.10.1 (build 11.0.18+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.18.10.1 (build 11.0.18+10-LTS, mixed mode)

Library Dependencies

WS

Code to reproduce the issue -

def test = Action.async { implicit request =>
    val res = ws.url("").stream()
    println("after request " + LocalDateTime.now())
    res.map {
      f =>
        println("Inside future " + LocalDateTime.now())
        Ok.chunked(f.bodyAsSource)
    }
  }

Expected behaviour -
The code execution inside the res future as soon as first bytes are received.

Actual behaviour -
The code execution inside future does not start till the file is downloaded.

after request 2023-05-19T23:30:43.941997
Inside future 2023-05-19T23:31:05.353642

Roughly 20 seconds have passed when the code execution reaches inside the res future. It is the same amount of time to download 150MB of image on my network.

I get the same effect if I use .get() instead of .stream()

@guillaumebadin
Copy link

guillaumebadin commented Jun 7, 2023

It seems we have performance problème since play 2.8.19 with Play Streams (Akka Streams ?).

        success =>
          success.warnings foreach { w => logger.warn(s"$context Warning: <<<${w.value}>>>") }
          val a: Source[ByteString, Unit] = StreamConverters.fromInputStream(() => success.inputStream).mapMaterializedValue(_.onComplete(_ => success.inputStream.close()))
          Ok.streamed(
            a, None, false,
            Some(s"${resultId.value}_-_${
              success.metadata.oneMatch.hprimFileS3Key
            }_-_${
              success.metadata.oneMatch.attachmentFileNameInHprim
            }")
            ).as(applicationPdf)

We have a crazy leaks since this version.

@guillaumebadin
Copy link

guillaumebadin commented Jun 7, 2023

@mohittt8 did you fix your issue by downgrading play or Akka version ?

@mohittt8
Copy link
Author

mohittt8 commented Jun 7, 2023

@guillaumebadin - We have started using Akka Http.

@mkurz
Copy link
Member

mkurz commented Aug 19, 2023

Can you please tell exactly from which version you upgraded to what version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants