Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open-next V3 #3567

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Open-next V3 #3567

wants to merge 11 commits into from

Conversation

conico974
Copy link
Contributor

@conico974 conico974 commented Dec 7, 2023

This PR add supports for open-next V3.
It should support all the features of open-next V3.
This PR also added some new things in the cloudfront function to improve cache hit ratio by a lot
It requires OpenNext v3, latest at the time of writing is 3.0.0-rc.13

Here is a simple example to use this construct:

import {NextjsSite} from "sst/constructs"

import type {OpenNextConfig} from "./open-next.config";

const site = new NextjsSite<OpenNextConfig>(stack, "site", {
  openNextVersion: "3.0.0-rc.13",
  logging: "combined", // per route logging is not implemented yet
  waitForInvalidation: false,
  cdk: {
    servers: {
      pageSsr: {
        cpu: "0.5 vCPU"
      },
      ssr: {
        memorySize: 512,
      },
      default: {
        memorySize: 1536,
      },
      middleware: {
        memorySize: 256
      }
    },
  
  }
});

This is mostly done, there is still some things that need to be figured out before release

  • Do we want the external middleware to be in front of cloudfront ?
  • Right now it works with ECS as well as lambda, do we want to allow other deployment method (EC2, App Runner, EKS) This has been removed, could be added again later
  • Should we move more logic into SSRSite ?
  • Reimplement per route logging
  • Makes warmer work with multiple lambda This should work now, but it might have broken other framework (Not tested)

Copy link

changeset-bot bot commented Dec 7, 2023

⚠️ No Changeset found

Latest commit: 5ab11fe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@khuezy khuezy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I haven't deployed this latest version yet though.

bundle: path.join(sitePath, fn.bundle),
runtime: "nodejs18.x" as const,
architecture: Architecture.ARM_64,
memorySize: 1024,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should default the lambdas to 1536MB, see: https://docs.aws.amazon.com/lambda/latest/operatorguide/computing-power.html

tl;dr - 1536 MB is almost as cheap as 128 MB but you also get max speed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that's strictly true. The AWS table provided is an example, they explain that by increasing memory you also increase vCPU given and that for CPU bound operations it will be cheaper as the function will run faster.

But if it doesn't complete faster, it'll just be more expensive. That's why they've got a complicated tool to measure and profile your services ideal memory:

Without benchmarking and testing an "average" nextjs app with different memory configurations, I think 1024 sounds like a reasonable default

Copy link
Contributor

@khuezy khuezy Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. It's a bit tricky b/c there's been several people getting slow latency from certain dependencies like prisma and increasing the memory helped minimize it. But everyone's mileage may vary.

mode: this.doNotDeploy
? ("placeholder" as const)
: ("deployed" as const),
path: this.props.path,
runtime: this.props.runtime,
customDomainUrl: this.customDomainUrl,
url: this.url,
edge: this.edge,
// edge: this.edge,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

@@ -38,7 +38,7 @@ import { SsrFunction } from "./SsrFunction.js";
import { Asset } from "aws-cdk-lib/aws-s3-assets";
import { useFunctions, FunctionProps } from "./Function.js";
import { useDeferredTasks } from "./deferred_task.js";
import { Logger } from "../logger.js";import { SsrContainer, SsrContainerProps } from "./SsrContainer.js";
import { Logger } from "../logger.js"; import { SsrContainer, SsrContainerProps } from "./SsrContainer.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line?

@conico974 conico974 marked this pull request as ready for review April 5, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants