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

Colocate Graphql Apollo Server in this repository #113

Merged
merged 13 commits into from
Jan 28, 2020
Merged

Conversation

poulainv
Copy link
Owner

This is an attempt to deploy an Apollo Server using Prisma2 to Now.
Let's monitor it to see how much does the cold start impact performance.

@vercel
Copy link

vercel bot commented Jan 22, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/quiet/quiet/lymkeiokz
✅ Preview: https://quiet-git-prisma2-now.quiet.now.sh

@poulainv
Copy link
Owner Author

Serverless functions are well deployed and graphql endpoint is available there: https://quiet-git-prisma2-now.quiet.now.sh/graphql

Build logs show that TS 3.7 is used

Using TypeScript 3.7.4 (local user-provided)
--
12:50:02 PM | Build completed. Populating build cache...
12:50:02 PM | Build cache uploaded [0.00 B]: 53.089ms
12:50:02 PM | done

But still 2 issues.

  1. Build time
    Prisma client (Photon) is not generated cause it did find schema declaration
Error: Can't find schema.prisma
  1. Runtime. Seems that TS 3.7 is not used
2020-01-22T11:53:46.633Z	undefined	ERROR	/var/task/api/src/schema/Object.js:94
                    where: { authUserId: user?.auth0Id },
                                              ^

SyntaxError: Unexpected token '.'
    at Module._compile (internal/modules/cjs/loader.js:892:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/zeit/56c87e93/api/src/schema/index.ts:4:1)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)END RequestId: 7338ebe9-3766-44aa-b098-e569e55967de
Duration: 702.61 ms  Billed Duration: 800 ms  Memory Size: 3008 MB  Max Memory Used: 70 MB	
RequestId: 7338ebe9-3766-44aa-b098-e569e55967de Error: Runtime exited with error: exit status 1
Runtime.ExitError

@poulainv
Copy link
Owner Author

poulainv commented Jan 23, 2020

I temporary removed TS 3.7 syntax to perform some experimentations.

Prisma2 version 2.0.0-preview019
PG: RDS db.t2.micro from AWS free tier hosted in eu-west-1 regions

Different queries complexity on different envs

Simple query
{
    items (where: {isDeleted: {equals: true}}) { 
        id
    }
}
Complex query
query getSections($authUserId: String!) {
    sections(
        where: {
            isDeleted: { equals: false }
            owner: { authUserId: { equals: $authUserId } }
        }
    ) {
        id
        createdAt
        isExpanded
        title: name
        collections(
            where: { isDeleted: { equals: false } }
            orderBy: { createdAt: asc }
        ) {
            id
            slug
            isDeleted
            title: name
            items(first: 4) {
              id
              title
              author
            }
        }
    }
}

Executed on playground graphql both against heroku standalone deployment & serverless lambda environment.
Used resolvers are defined with Nexus.

Here's the results

Query Heroku Standalone simple Dyno Now Serverless Gzipped size
Simple 100ms 660ms 3Kb
Complex 180ms 2890ms 6.5Kb

Now Functions is deployed on the default region that seems to be sfo1 (now region id) us-west-1 (aws region id).

UDPATE:

Got much better performance results by deploying Now Functions on eu-west-1 to colocate it with RDS instance

Query Heroku Standalone simple Dyno Now Serverless Gzipped size
Simple 100ms 150ms 3Kb
Complex 130ms 180ms 6.5Kb

Probably due to n+1 problem, where many roundtrips are much more impacted by db latency.

@vercel vercel bot temporarily deployed to Preview January 28, 2020 18:38 Inactive
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.

1 participant