CPU [                         0.0%]     Tasks: 15, 2 thr; 1 running
Mem [||||                 14/256MB]     Load average: 0.00 0.00 0.00 
Swp [|                     1/256MB]     Uptime: 15 days, 06:02:31

Above is the memory usage on my server (Ramnode, 256MB RAM with 256MB Swap) when there's no Ghost instance. On my VPS I am running 4 Ghost instances.

So when I ran a Ghost instance here with the command node index.js, it spawns 5 workers.

10380 user    20   0  975M 80328  7712 S  0.0 30.6  0:00.00 node index.js
10381 user    20   0  975M 80328  7712 S  0.0 30.6  0:00.00 node index.js
10382 user    20   0  975M 80328  7712 S  0.0 30.6  0:00.00 node index.js
10383 user    20   0  975M 80328  7712 S  0.0 30.6  0:00.00 node index.js
10384 user    20   0  975M 80328  7712 S  0.0 30.6  0:00.00 node index.js

5 workers are actually quite a lot. And 30% is also a lot.

And now, the htop reading

CPU[                               0.0%]     Tasks: 18, 7 thr; 1 running
Mem[|||||||||||||||||||        82/256MB]     Load average: 0.00 0.00 0.00 
Swp[||                          8/256MB]     Uptime: 15 days, 06:22:29

How to reduce the memory usage? If I can adjust the number of workers, which file should I edit? If we have Ghost dev team here, do you have any plan on this issue?

  • 5
    I thought NodeJS was supposed to be super lightweight. Sep 29 '14 at 18:45
  • 1
    @gtirloni exactly my point here! Sep 29 '14 at 19:21
  • That's already very lightweight! Sep 30 '14 at 12:48
  • 1
    I started a Hello World Node app for comparison, and found it uses 65MB, so that means the Ghost app is only adding 15MB. And that's the whole app in memory at once (unlike say a PHP webapp which loads only part of the app for any given request). Well, I guess this is lightweight for 2014/15. imgur.com/gallery/uqKOX Dec 15 '15 at 15:49
  • But having said that, top here reports my running ghost app uses 37876k under the RES column, which differs significantly from yours. (Node v0.10.37 on a DigitalOcean "Intel Xeon".) Dec 15 '15 at 15:53

Ghost runs a single node process per instance. I believe what you're seeing there is that htop shows the underlying threads of processes, so it looks like you have one Ghost instance running but node/v8 has five active threads. Despite JavaScript being single-threaded, the engine/vm itself can be multi-threaded.

We (the Ghost project) do pay attention to the memory footprint so that we can do whatever we can do keep it as small as possible. I personally think 80MB is pretty good but obviously different people and situations have different criteria for what's "pretty good."

  • 3
    Thanks for the answer @jtw. So 80MB is considered as lightweight. My personal thought on this matter is that 80MB for a less 20 visitors per day is quite overkill. Oct 1 '14 at 1:26
  • 1
    @AizanFahri "lightweight" is not really an objective term but in general, for a package that does as much as Ghost, I think 80MB is a pretty reasonable memory footprint. If your concern is being able to get 4 Ghost blogs running on a single 256MB VPS, I suspect you can pull that off--especially if they are low traffic. There will be some memory savings due to the multiple node processes being able to share some memory.
    – jtw
    Oct 1 '14 at 1:40
  • 1
    I'l echo @jtw here -- 80Mb is quite good, but what's more important to track is whether that number stays constant. If it slowly goes up, that's indicative of a memory leak, and ought to be tracked down and squashed. Oct 2 '14 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.