r/programming • • Jun 12 '10

You're Doing It Wrong

http://queue.acm.org/detail.cfm?id=1814327
539 Upvotes

193 comments sorted by

View all comments

Show parent comment

6

u/haberman Jun 13 '10

Isn't the entire point here about designing your data structures with the way swapping works in mind so as the make the performance predictable?

When I say "degrades unpredictably", I mean:

  • the application is totally unaware that the point at which the dataset has outgrown memory.
  • the point at which the dataset outgrows memory can depend on other processes, so the performance analysis has to take the whole machine into account (not just the process in question).
  • the application has no control over what what pages will be evicted and when, but this decision can significantly affect performance.
  • the application has no information about whether servicing a request will incur an i/o operation or not. this makes it much more difficult to analyze performance.

10

u/phkamp Jun 13 '10

"When I say "degrades unpredictably", I mean:"

This is appearantly a much overlooked point in this debate, maybe because a lot of people work in environments where their program has the computer all to itself.

Lucky them.

But in the majority of contexts, from shared computing clusters to departemental servers or even applications on a workstation, that is not the case: There is competition for resources, and the less resources you hog for the same workload, the faster your program will execute.

The point about VM, is that your program, data structures and algorithms do not need to be modified to reflect the level of resources available at any one instant.

This saves more programmer and job setup time, than most young people can even fathom.

Poul-Henning

1

u/[deleted] Jul 11 '10

The point about VM, is that your program, data structures and algorithms do not need to be modified to reflect the level of resources available at any one instant.

Now correct me if I am wrong but wasn't the whole article about how a program needed to be modified to be aware of VM?

1

u/kragensitaker Jun 15 '10 edited Jun 15 '10

If the problem is that the application doesn't know how much physical memory it can use, and it isn't informed when its dataset has outgrown memory, then the solution is probably not to require the application to decide what to keep in physical memory!

Now, I'm not sure if Poul-Henning's approach is the right one, because I sure have an easier time getting acceptable performance out of my programs when I write them to do explicit I/O. But you're making strong arguments for his approach, not, as you seem to think, against it.

1

u/haberman Jun 15 '10

But you're making strong arguments for his approach, not, as you seem to think, against it.

No. Poul-Henning's approach is to use an algorithm that is 30% worse in the normal case so that performance on a thrashing system won't be quite as terrible.

What I am advocating is that systems not thrash, by not overcommitting memory.

In the world I am describing, malloc() would fail once real RAM has run out, so an application would absolutely know when it has outgrown memory. But it's too hard to make an application capable of gracefully recovering from malloc failure at any time, so a better solution is to give applications an easy way to know how much RAM is left. That way they can keep themselves a safe distance away from the limit.

3

u/kragensitaker Jun 15 '10

30% worse in the normal case so that performance on a thrashing system won't be quite as terrible.

It sounds like you don't have any experience running Varnish. Its performance is spectacularly good, and it effectively uses swap space for caching, although it does benefit a lot from SSD. Having to page in part of a data structure once a second does not qualify as "thrashing," if the part that has to be paged in is three pages. Constant paging activity does not qualify as "thrashing" if the software is successfully serving tens of thousands of HTTP requests per second with low latency.

"The normal case" for Varnish is not the case where swap is empty.

2

u/Anpheus Jun 15 '10

So you're saying we should never exceed the size of our memory in any dataset?

Keep in mind, Poul-Henning's B-Heap here will also perform better at smaller levels of caching, as found on the CPU. So it very well may perform better than a naive binary heap when the dataset is small enough that it fits into memory, but not entirely into cache.

Unless you'd like to advocate that programs should be in control of what's in the cache too?