Is swap a bad thing?

I am running my application on a 512 linode and due to some extra in memory processing I have just developed in the application I have noticed that it is starting to use the swap space. At the moment the application gets very little traffic so I guess using swap space is not a problem. If I was to start getting much more traffic would using swap space start to slow the application down?

In this case can I assume just upgrading to a larger linode with more memory would remove the problem? I do not cache anything in memory its just the fact that I load 1-20mb of data to process per page request.

7 Replies

I had the same problem some time ago. Moving to a larger Linode worked for me.

James

Gonna hijack this thread.. My memory usage is ~250 mb out of the 512 but it's using 62 MB swap.. is that a bad thing?

swapping out is good, swapping in is bad.

run

vmstat 1

and watch the si and so columns, if there's constant activity, you need to do something.

you should get to know what's normal and what's not, so run it often so when things do become slow or OOM, you'll know what it's meant to look like. That goes for all monitoring tools, like top, etc.

If you're using apache prefork and especially if you're using mod_php, you need to modify maxclients and possible keep-alives to make your server degrade gracefully under a high web load, otherwise with the default settings, your vps will OOM and require a reboot, whereas if you tune apache, your web sites will be very slow to load under a high web load, but your vps will be up and happy, you'll be able to log into it, etc.

I won't go into all the details, you can find guides in the library or on google.

Sorry for the really slow replies. Took a while to get used to these things. I shall keep tabs on that. Thanks!

if you use your swap space. there will be a considerable slowness in your application

@nalanda:

if you use your swap space. there will be a considerable slowness in your application
As chesty said, that's only a problem if you're swapping in a lot. If you swap out a chunk of some daemon that starts on boot and then does nothing ever, it actually helps performance, since it's more useful to use the RAM for the disk cache.

Which is why it's good to have a little bit of swap, but not much. I'd say you should have 1/4th or 1/8th of your RAM as swap, just to give you enough room to take some of that unnecessary stuff out of RAM, but not enough to cause slowdowns.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct