balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.81k stars 1.95k forks source link

startup profiling/performance tuning #6911

Open alxndrsn opened 4 years ago

alxndrsn commented 4 years ago

Has anyone got any tips to share regarding the following?

  1. measuring which parts of sails are taking the longest during startup,
  2. specific issues/patterns to look out for which will slow startup,
  3. getting sails to start faster?
sailsbot commented 4 years ago

@alxndrsn Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

johnabrams7 commented 4 years ago

@alxndrsn For faster startups or startup diagnostic, it's worth verifying/optimizing/cleaning-up the bootstrap, database configuration, and/or any custom modules added to the default set included with app. Upgrading database adapters or Sails itself when feasible may potentially improve startup performance as well.

As for specifically measuring startup performance, sails lift --verbose and sails lift --silly (even more detail) display various module startup times in milliseconds and the lift itself ultimately displays the completed startup timestamp for the entire app (in whole seconds).

Screen Shot 2019-12-16 at 6 32 58 PM

Great for profiling specific module startup times, however, the total app startup time isn't displayed as far as I know, but I can check with the team for any potential ways to extract that info.

I think there might be a way to tweak this further to display the start/end times in milliseconds with a console timelog script as another startup profiling technique. As for 3rd party tools, I'll keep an eye out and report back any significant ones for startup testing.

Here's a Gitter post by the founder covering further performance optimization philosophy for Sails - also related to database management. Scalability and reliability of the system / architecture hosting the app also play a role in startup performance (other side of the coin in comparison to code optimization).

Also found some additional Sails startup performance advice on Stackoverflow.

Hope this helps so far. I like the idea of having a total milliseconds of the app startup time show next to the lift timestamp -- e.g. debug: :: Mon Dec 16 2019 18:25:57 GMT-0600 (CST) (4230ms)

alxndrsn commented 4 years ago

Upgrading database adapters or Sails itself when feasible may potentially improve startup performance as well.

Interesting point. Are you accepting patches for sails-postgresql/machinepack-postgresql? They currently depend on node-postgresql version 6.1.6, which is more than two years old.

johnabrams7 commented 4 years ago

@alxndrsn Sure, we can take a look at them - are they specifically to update node-postgresql?

alxndrsn commented 4 years ago

@johnabrams7 yes, but I'm curious the difference it makes because:

I appreciate the burden of maintaining open source software, plus all the hard work that's gone into the Sails framework and supporting library, and I get the impression that support for these two packages is effectively on hold and they are already deprecated in favour of the impending sails-sql adapter (see various comments including https://github.com/balderdashy/sails/issues/6817#issuecomment-513333171, https://github.com/balderdashy/sails/issues/6820#issuecomment-515169117, https://github.com/balderdashy/sails/issues/6880#issuecomment-555219021, https://github.com/balderdashy/sails/issues/6888#issuecomment-555215340).

However, sails-sql still hasn't reached 1.0, hasn't had a public release for 9 months, and hasn't had a public commit since April 2019.

Is there anything I can do to help expedite PR review/merge or otherwise help with PosgreSQL support? If I were to submit a PR for updating the node-postgresql dependency for sails-postgresql, what is the chance of getting that released? Would it be more productive, and helpful to the community, if I were to actively support a PostgreSQL-focussed fork of sails-postgresql?

johnabrams7 commented 4 years ago

@alxndrsn Wanted to follow-up. How are you doing on the startup profiling/performance tuning for this one?

alxndrsn commented 3 years ago

Some ideas for profiling SailsJS startup can be found at https://kevin.burke.dev/kevin/node-require-is-dog-slow/, but note that this blogpost is from 2015.