简体   繁体   中英

Sails js application driving CPU usage to 100%

I'm building a an application using sails and every time I leave the server running for more than a few minutes my CPU jumps to a solid 100% usage. I'm including a big amount of less files in my assets and I believe my issue lies here. Are there any other reasons this may happen?

It could be the grunt-watch, when you have a lot of files it squeezes your cpu. Try disabling that and check if your cpu gets to a normal usage (6-30% depending on your cpu and overall usage).

To do that go to tasks/register/default.js and remove 'watch' from the array.

module.exports = function (grunt) {
    grunt.registerTask('default', ['compileAssets', 'linkAssets',  'watch']);
};

If you don't want to completely disable the grunt watcher, then go to tasks/config/watch.js and try excluding the folder that has most of your files, or exclude them all if they are not in a particular folder.

I'll give you an example of how to exclude a folder for this task. Just add a ! before the path you want to exclude.

module.exports = function(grunt) {

    grunt.config.set('watch', {
        // Some config you can ignore in this case
        assets: {

            // Assets to watch:
            files: ['assets/**/*',
              'tasks/pipeline.js', '!**/node_modules/**',
              '!assets/folder-to-exlude/**' // <-- HERE IS THE EXCLUDED PATH
             ],

            // More code
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
};

I had a similar issue and this worked for me, let me know if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM