0

I know how swapping basically works, why it's automatic and why it's generally a good thing.

There is, however, a common scenario where I wish I had more control.

I write LOB web applications with IIS and Sql Server (this question is more general than that though).

Those applications are hosted on dedicated servers (or virtual machines on those) and used infrequently. It can happen that they aren't used for hours. When the next user then makes a request, the first database request to SqlServer usually takes at least a couple of seconds. And that's not even counting other components of the stack that need to wake up as well.

I would think this is at least in part due to IO that really should have been avoided since it had that information in memory once. (The queries had been run before at some point in the past.)

The machine also runs a virus scanner (company policy), and my guess is that after a sweep of that all other processes are entirely swapped out. And besides virus scanners, there are sometimes other maintenance processes that over time can temporarily consume memory.

I wouldn't even mind the application stack to be put to sleep temporarily, as long as it's put back in memory when the machine becomes idle again - but I don't think this is how it works.

This sounds like a very general problem that basically all people have who deploy applications with a more infrequent usage. It also applies to all operating systems, web servers and databases.

Of course I know I could make regular dummy requests that keep the server busy - and in fact I'm already doing that to keep the non-database part of the stack.

What else can be done here? Especially, what can be done economically and practically?

John
  • 123
  • 7

1 Answers1

0

All this depends on how you set up the virtual machine and the guest OS. If you reserve all guest memory you can be sure that it's never swapped out (which shouldn't happen with decent provisioning anyway).

Within the guest, there should be enough memory to avoid swapping out anything. Ideally, there should be no or extremely low swapping.

Additionally, you might want to make sure that your VM also gets processing power when it's required, so you might need to reserve some hundred MHz as well.

Economically, all this costs you expensive host resources. You'll need to find out reasonable minima for the reserved resources in order to avoid reserving everything. If you do that you gain little by virtualizing the machine.

Zac67
  • 8,639
  • 2
  • 10
  • 28
  • "Within the guest, there should be enough memory to avoid swapping out anything." How could that be possible? Wouldn't a virus scanner reading everything on the disk lead to the OS use up all RAM for caching in the absence of anything deemed more important? – John Jul 15 '17 at 08:58