https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • v

    vans163

    07/27/2021, 3:55 PM
    i am aware of doing inside the worker
    Copy code
    let { readable, writable } = new TransformStream()
            request.body.pipeTo(writable)
  • k

    kenton

    07/27/2021, 3:56 PM
    Same code should work in durable objects.
  • v

    vans163

    07/27/2021, 3:56 PM
    but how would i forward the POST request into the DO? same as a websocket? and negotation the transformstream inside the DO?
  • v

    vans163

    07/27/2021, 3:57 PM
    also this pipe way, is for streaming 2 requests into eachother (example using workers as a proxy) but i did not see a way to read the chunks on the fly
  • k

    kenton

    07/27/2021, 3:58 PM
    Your stateless worker can directly forward a request it received to a DO, like
    objectStub.fetch(request)
    where
    request
    is the original request it received...
  • v

    vans163

    07/27/2021, 3:58 PM
    so get into the DO like this from the worker?
    Copy code
    let id = env.OBJECT.idFromName('user1')
            let obj = env.OBJECT.get(id)
            return obj.fetch(request.url, request)
  • k

    kenton

    07/27/2021, 3:59 PM
    just
    obj.fetch(request)
  • v

    vans163

    07/27/2021, 3:59 PM
    yes in my case the request is streaming (so it has many chunks sent over a period of 30+seconds)
  • k

    kenton

    07/27/2021, 3:59 PM
    that's fine, streaming will work
  • k

    kenton

    07/27/2021, 4:00 PM
    see https://developers.cloudflare.com/workers/learning/using-streams
  • v

    vans163

    07/27/2021, 4:00 PM
    any idea then on the DO end how to get a callback for data chunk on the body? guessing some kind of pipe needs to be extracted from request.body() ?
  • k

    kenton

    07/27/2021, 4:00 PM
    request.body
    is a
    ReadableStream
    . https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
  • v

    vans163

    07/27/2021, 4:01 PM
    yes but I want the other end of the stream to dump into the DO memory
  • v

    vans163

    07/27/2021, 4:02 PM
    that example only shows how to connect a pipe, (example to proxy a request betwwen another endpoint) so when the endpoint writes, it wont stall waiting for full reply)
  • v

    vans163

    07/27/2021, 4:02 PM
    ah maybe this https://developers.cloudflare.com/workers/runtime-apis/streams/readablestreambyobreader
  • v

    vans163

    07/27/2021, 4:03 PM
  • v

    vans163

    07/27/2021, 4:03 PM
    ah yea but no biggie
  • v

    vans163

    07/27/2021, 4:04 PM
    kk working..
  • v

    vans163

    07/27/2021, 4:15 PM
    oh wait this probably wont work because the DO will die once it exceeds the CPU limit (single fetch request CPU limit)?
  • k

    kenton

    07/27/2021, 4:25 PM
    Yes, the CPU limit only get refreshed each time a new request arrives. Stream chunks don't count and new requests. Currently the limit is 500ms, but will be extended to 30s when we start billing -- maybe that's enough?
  • v

    vans163

    07/27/2021, 4:26 PM
    500ms not enough, 30s probably
  • v

    vans163

    07/27/2021, 4:26 PM
    Copy code
    while (1) {
            var view = new Uint8Array(8388608);
            const { value, done } = await reader.read(view);
            if (done) {
                break;
            }
        }
  • v

    vans163

    07/27/2021, 4:26 PM
    i read for some reason the
    view
    becomes detatched here, no idea what detached means. does it mean it cannot be reused? this code seems really silly
  • v

    vans163

    07/27/2021, 4:26 PM
    the buffer should obv be reused? (declared outside the loop)
  • v

    vans163

    07/27/2021, 4:27 PM
  • w

    Wallacy

    07/27/2021, 4:42 PM
    I did a similar math on my side and im keeping the memory cache for the same reason. I read 100-1000x more from memory than from storage accounting everytime the object is (for any reason) reinitialized. If read from cache can have a lower price tier i will probably remove my memory map.... apps are constrained by cost all the time, thats not a surprise.
  • w

    Wallacy

    07/27/2021, 4:45 PM
    Thats explain few erros that i got... Nice to know!
  • v

    vans163

    07/27/2021, 4:45 PM
    yea basing costs of AWS is silly too as its just so overpriced inherently and many of their payment models dont make sense in relation to the underlying costs of the hardware/network
  • v

    vans163

    07/27/2021, 4:48 PM
    example pricing things in "requests" why not just measure the instructions executed using eBPF or something and give a price per instruction based on clockcycles taken
  • v

    vans163

    07/27/2021, 5:22 PM
    @User any idea why this is so expensive
1...131132133...567Latest