Code Monkey home page Code Monkey logo

Comments (6)

trowski avatar trowski commented on May 24, 2024

Hi @vikingjs!

ReadableIterableStream and ConcurrentQueueIterator do not retain values once they have been consumed.

QueueState (the class underlying the implementation of Queue and ConcurrentQueueIterator) unsets values when they are set to the FiberLocal. See line 86 in QueueState.php.

It sounds to me as though there might be some other bug causing a memory leak or you're buffering the data read, which of course is going to consume that memory as well.

from byte-stream.

vikingjs avatar vikingjs commented on May 24, 2024

That's good to know. The error I'm getting is Amp\Http\Client\ParseException: Configured body size exceeded: so I don't know how code outside the stream would cause it. Perhaps I'm not consuming as quickly as I thought I was.

I will slow down the server side to see what that does for the buffer.

I'm tempted to try to parallelize reading off that stream, but occasionally two reads are required to instantiate one resulting object. Do you know a way to manage that? It's a case where a single item written into the stream on the server requires two reads on the client.

from byte-stream.

vikingjs avatar vikingjs commented on May 24, 2024

This seems strange in SizeLimitingReadableStream:

        $chunk = $this->source->read($cancellation);

        if ($chunk !== null) {
            $this->bytesRead += \strlen($chunk);
            if ($this->bytesRead > $this->sizeLimit) {
                $this->exception = new ParseException(
                    "Configured body size exceeded: {$this->bytesRead} bytes received, while the configured limit is {$this->sizeLimit} bytes",
                    HttpStatus::PAYLOAD_TOO_LARGE
                );

                $this->source->close();
            }
        }

The body size limit is not applied to the amount of data in the body, but the overall amount read. How do I get out from under the tyranny of this class?

from byte-stream.

trowski avatar trowski commented on May 24, 2024

The HTTP client has a default body size limit (10MB) which can be configured on the Request object using setBodySizeLimit(). This exists to allow completely buffering a response body without worry of consuming too much memory. Since you're streaming the response body, feel free to make this number huge, even just using PHP_INT_MAX to effectively turn off the size limit.

from byte-stream.

vikingjs avatar vikingjs commented on May 24, 2024

That's basically what I have done now. I was hoping to remove that dang thing from the chain as it adds only negative value, but I can get over it. Thanks for your help!

from byte-stream.

trowski avatar trowski commented on May 24, 2024

It appears we may have intended a body size of 0 to turn off the limit (e.g. this use), but seems we may want to follow through on that, adding the check elsewhere and skip creating SizeLimitingReadableStream if it's not necessary.

I wouldn't concern yourself over an extra method call per chunk. There's a lot more CPU going to decompressing the response body.

from byte-stream.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.