ItsWendell
08/15/2021, 10:48 AMItsWendell
08/15/2021, 10:48 AMalbert
08/15/2021, 10:49 AMsetInterval()
still use memory though?albert
08/15/2021, 11:13 AMalbert
08/15/2021, 11:15 AMItsWendell
08/15/2021, 11:29 AMItsWendell
08/15/2021, 11:32 AMalgads
08/15/2021, 11:49 AMItsWendell
08/15/2021, 12:05 PMWallacy
08/15/2021, 12:16 PMWallacy
08/15/2021, 12:16 PMWallacy
08/15/2021, 12:17 PMWallacy
08/15/2021, 12:17 PMalbert
08/15/2021, 1:36 PMjs
async function handleRequest(request, env) {
const start = Date.now()
const url = new URL(request.url)
const id = env.VOLATILECOUNTER.idFromName(url.pathname)
const stub = env.VOLATILECOUNTER.get(id)
while (true) {
const response = await stub.fetch(request)
const stop = Date.now()
if (response.status == 200) {
return new Response(JSON.stringify({start: start, stop: stop}), {headers: {'content-type': 'application/json'}})
}
await new Promise(resolve => setTimeout(resolve, Math.random() * 10))
}
}
Durable Object:
js
export class VolatileCounter {
constructor(state, env) {
this.state = state
}
async initialize() {
this.value = 0
}
async fetch(request) {
if (!this.value) {
await this.initialize()
}
this.value++
return new Response(this.value)
}
}
These results come from 10 HTTP/2 parallel connections (on different cores) each making 2000 parallel requests. The response time of the Durable Object was measured inside the Worker using as can be seen in the code.albert
08/15/2021, 1:47 PMalbert
08/15/2021, 1:48 PMErwin
08/15/2021, 2:04 PMalbert
08/15/2021, 2:08 PMalbert
08/15/2021, 2:08 PMjs
while (true) {
const response = await stub.fetch(request)
const stop = Date.now()
if (response.status == 200) {
return response
}
await new Promise(resolve => setTimeout(resolve, Math.random() * 10))
}
albert
08/15/2021, 2:09 PMreturn stub.fetch(request)
, I start getting status 500 under heavy load.albert
08/15/2021, 2:10 PMkenton
08/15/2021, 4:12 PMawait
inside the try/catch), then you should be able to catch any exceptions and they should have descriptions that explain what went wrong.kenton
08/15/2021, 4:13 PMalbert
08/15/2021, 4:15 PMjohn.spurlock
08/15/2021, 5:51 PMMap
of all instances, adding this
to the static container in your DO constructor, you can easily make direct in-memory calls between them. However, if an instance gets a handle to another instance's state.storage
, it is prevented from making I/O calls on it. Error: Cannot perform I/O on behalf of a different Durable Object. I/O objects (such as streams, request/response bodies, and others) created in the context of one Durable Object cannot be accessed from a different Durable Object in the same isolate. This is a limitation of Cloudflare Workers which allows us to improve overall performance.
ItsWendell
08/15/2021, 6:55 PMGreg-McKeon
08/15/2021, 8:07 PMGreg-McKeon
08/15/2021, 8:10 PMalgads
08/15/2021, 10:55 PMjohn.spurlock
08/15/2021, 11:18 PM