Simple SvelteKit deploy on Page exceeds CPU because one server side call

I was following the tutorial to deploy SvelteKit website through pages.
I have one +page.server.ts file where I load some json data from a public api (for test reasons).

import type { PageServerLoad } from './$types';
export const load = (async ({ fetch, params }) => {

    const all_ep_res = await fetch('');
    const all_ep_data = await all_ep_res.json();

    return {
        episodes: all_ep_data
}) satisfies PageServerLoad;

So I deployed this, and tried to browse to this page.

After two clicks I got:

This is a very simple api call; CPU exceeded because of this?

The CPU time is likely from calling .json() which is having to parse the ~3.3MB of JSON returned by the API you’re calling.

See if you can reduce the amount of data returned - i.e with a limit or pagination.

In this case, this could be a possibility; but I guess there are situations where you need to process such large list…

Is there a way to avoid such “exceed” up front?

Workers on the free plan are limited to 10ms of CPU time and the paid plan has two usage models - Bundled which has 50ms and Unbound which has up to 30 seconds but you are billed for wall-time duration when using Unbound.

Bundled sounds like it should work fine for your use-case if you upgrade? But otherwise, other than not calling json(), I can’t think of any real workaround.

And how do you “choose” between the two usage models; If I see to the paid plan, I see both, but not sure how I should select one or the other, or is this something you need to configure?

Found in the docs that you can configure it; of course, the SvelteKit deployment does not uses explicit worker functions; it’s baked into the “adapter”. So not sure if 50ms of CPU is “enough” in this case?

For the Pages project, go into Settings and then Functions.

Svelte just compiles all of your routes into a Worker on your behalf - it shouldn’t really make a difference.

So if, for some reason, the http cpu time is larger than 50ms, the site goes down because of the CPU exceeding limations; how long will it be down, or only for that specific IP/user, all users?

Workers (and by extension Functions) are invoked on request - if the CPU limit is reached, that only impacts that specific request. They can just refresh the browser and try again.

Ok, thank you for the very clear feedback! It was helpful.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.