Workers what part counts towards the cpu Costs

Hi, I am still not clear. If I have a worker that does 3 things. 1) Reads a KV image 2) Processes it (say increases its brightness) 3) Streams the image to a client.

What part counts toward the cpu processing time and is thus charged. Example: If it takes 1) Total 100 ms to read image from KV image into a JavaScript variable say type arrayBuffer in chunks2) 30 ms to process it 3) Total 200 ms to stream it to the client.
Are we paying for 330 ms? Thanks!

Workers charges by the number of requests. CPU only comes into play when it comes to time limits. The Paid plan for Workers allows requests up to 50ms.

Have you been using Workers already? The Workers page here shows Median CPU time for that worker.

1 Like

I am using in Development phase, so unable to see not much data processing, but these questions in my mind are for future concerns, and also how much to depend on workers compare to how much to depend on API direct KV access. Thanks for your time to answer the concerns.
I am still not clear. In the above question I used may be wrong example or wrong words. For a second ignore the 50ms limit (say, I was able to buy larger time for each slot.) The question is the 330 seconds above will it be completely charged. There is a concept like the FRAMETIME (time frame?), where the CPU is reading the image, but the actual processing is only 30 ms. Will 1) and 3) above included in the CPU time or not (the reading image from KV and the streaming part to client.)

Or if the 50 ms stays, will my worker crash because the total length is 330 ms (but 330 ms is not completely processing - there is some waiting for data phase).

Thanks

I have not seen a way to increase the 50ms limit. As for how CPU is actually measured, maybe @adaptive or @matteo can estimate based on your numbers.

1 Like

A new plan Workers Unbound is now in beta, that is the only way to achieve higher CPU.

2 Likes

Thank you @adaptive. So today if not using the Workers Unbound and having 50 ms total. If the total “time frame” for a request is 330 ms that includes the reading and process and then streaming time, will it fail .The actual processing time in this example is only 30 ms, used to say increase the image brightness, rest is the time to read a KV image and then time to stream it to the client. Thanks!

The limit is CPU time.

Most Workers requests consume less than a millisecond. It’s rare to find a normally operating Workers script that exceeds the CPU time limit. A Worker may consume up to 10ms on the free plan and 50ms on the Bundled tier. The 10ms allowance on the free plan is enough execution time for most use cases including application hosting.

There is no limit on the real runtime for a Workers script. As long as the client that sent the request remains connected, the Workers script can continue processing, making subrequests, and setting timeouts on behalf of that request. When the client disconnects, all tasks associated with that client request are canceled. You can use event.waitUntil() to delay cancellation for another 30 seconds or until the promise passed to waitUntil() completes.

2 Likes

Thank you!