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

Improve start-up time by not loading unused modules #9389

Open
oallouch opened this issue Oct 29, 2024 · 6 comments
Open

Improve start-up time by not loading unused modules #9389

oallouch opened this issue Oct 29, 2024 · 6 comments
Labels
type:question Support or code-level question

Comments

@oallouch
Copy link
Contributor

oallouch commented Oct 29, 2024

New Feature / Enhancement Checklist

Current Limitation

Because parse-server is compiling a lot of unused dependencies (Live Queries, Postgres, redis, ...), the startup is slow.
It prevents us from using Parse in cheap configurations of serverless hosting solutions, like Google Cloud Run with min-instances=0 .

Feature / Enhancement Description

Feature request : a fast startup,
prevent those unused dependencies from compiling, maybe by putting the imports inside conditions. For instance :

static async createLiveQueryServer(
    httpServer,
    config: LiveQueryServerOptions,
    options: ParseServerOptions
  ) {
    if (!httpServer || (config && config.port)) {
      var app = express();
      httpServer = require('http').createServer(app);
      httpServer.listen(config.port);
    }
    import { ParseLiveQueryServer } from './LiveQuery/ParseLiveQueryServer';
    const server = new ParseLiveQueryServer(httpServer, config, options);
    await server.connect();
    return server;
  }

Example Use Case

You're starting a new project. With a fast startup, you can have a nice server (4 Go and 2 CPUs) for almost nothing.
On Cloud Run, the CPU is turned off between requests, you only pay for the RAM, and after 15 minutes, the instance is unmounted. Add to this the fact that, in a month, 60 CPU-hours are free and 125 Go-hours are free.
But for this, you need to be able to have a fast startup. In my current project, a cold restart takes approximately 12 seconds. I think we could reach a few seconds.

Alternatives / Workarounds

I can put the min-instances to 1. When a second or third instance is started, Cloud Run waits before sending requests.
And between requests, when there's no CPU, you only pay for RAM and a special fee for "inactive instances".

Details

Here's a startup profile with all the unnecessary compiled code in red (at least 70% of all the compiled code).
It's on my big local machine. On the server, all time are multiplied by 4, at least.

There might be another problem : all the schemas are loaded at once to build the cache, but let's stick with the compilation issue for now :)

thx

Parse-server-startup

Copy link

parse-github-assistant bot commented Oct 29, 2024

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@mtrezza
Copy link
Member

mtrezza commented Oct 29, 2024

I'm closing this as it does not seem to be bug report or a feature request.

@mtrezza mtrezza added the type:question Support or code-level question label Oct 29, 2024
@mtrezza mtrezza closed this as completed Oct 29, 2024
@oallouch
Copy link
Contributor Author

I thought it would be a nice feature to communicate about.
Serverless is everywhere and being able have a very powerful server very cheap, for me, is a feature.

@mtrezza
Copy link
Member

mtrezza commented Oct 29, 2024

Was this indeed a feature request? Could you please edit your initial post by using the template provided when opening an issue to help clarify what specific feature you are requesting? Then we can re-open this.

@oallouch
Copy link
Contributor Author

I would like to try and do it myself, but I'm on Windows and it doesn't look like it's supported.

@mtrezza mtrezza added type:feature New feature or improvement of existing feature type:question Support or code-level question and removed type:question Support or code-level question type:feature New feature or improvement of existing feature labels Oct 31, 2024
@mtrezza
Copy link
Member

mtrezza commented Oct 31, 2024

Thanks for editing the post and using the template. It sounds like you'd suggesting to speed up the start time of Parse Server. A start-up time that is fast enough for you may not be fast enough for someone else, so in order to keep this open as a feature request, we'd need to specify an objective goal or metric by which the issue can be considered closed. For example, we already have open feature requests to move Postgres, GraphQL and other adapters out of the Parse Server code base. Or is there a quicker approach you are suggesting to implement in the meantime? Could Parse Server be optimized by just not loading certain modules in code if they are not configured in Parse Server? That would make sense I guess and probably shouldn't be too difficult to implement?

@Moumouls has experience with Parse Server running on serverless, maybe he has some input here?

@mtrezza mtrezza reopened this Oct 31, 2024
@mtrezza mtrezza changed the title Parse can't go 0 instance due to slow startup time Improve Parse Server start-up time by not loading unused modules Oct 31, 2024
@mtrezza mtrezza changed the title Improve Parse Server start-up time by not loading unused modules Improve start-up time by not loading unused modules Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

2 participants