Slashdot Mirror


Knuth Got It Wrong

davecb writes "Think you've mastered the art of server performance? Think again. Poul-Henning Kamp, in an article at ACM Queue, finds an off-by-ten error in btrees, because they fail to take virtual memory into account. And he solves the problem in the open source 'Varnish' HTTP accelerator, for all of us to see and use."

298 comments

  1. as Knuth told me when I was at his house by commodoresloat · · Score: 5, Funny

    "Who the hell are you and what are you doing in my house?"

    1. Re:as Knuth told me when I was at his house by interval1066 · · Score: 4, Funny

      I wrote Knuth an email once. He never wrote me back.

      --
      Python: 'And then suddenly you have a language which says "we're all stuck with whatever the whiniest coder wants".'
    2. Re:as Knuth told me when I was at his house by Meshach · · Score: 2, Funny

      "Who the hell are you and what are you doing in my house?"

      Get off my lawn.

      --
      "Maybe this world is another planet's hell"
      Aldous Huxley
    3. Re:as Knuth told me when I was at his house by MrEricSir · · Score: 3, Funny

      Next time, don't title your e-mail "buY h3rb@L c1aL 1s today!!"

      --
      There's no -1 for "I don't get it."
    4. Re:as Knuth told me when I was at his house by Ungrounded+Lightning · · Score: 2, Interesting

      I wrote Knuth an email once. He never wrote me back.

      As with the xkdc.org reference in the grandparent, this is something of an in joke. Don doesn't do email. B-)

      --
      Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
    5. Re:as Knuth told me when I was at his house by oldhack · · Score: 0, Redundant

      Why doesn't somebody tell me these things? I need to know stuff like this.

      --
      Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
    6. Re:as Knuth told me when I was at his house by TheGratefulNet · · Score: 5, Funny

      I called Wirth, once. but I think I called him by name and not by value.

      perhaps I made the wrong judgement call; my phone overflowed.

      --

      --
      "It is now safe to switch off your computer."
    7. Re:as Knuth told me when I was at his house by Anonymous Coward · · Score: 0

      Thanks, Oberon Kenobi!

    8. Re:as Knuth told me when I was at his house by Nebulo · · Score: 1

      To be fair, like many prominent authors, Knuth is probably very busy and has someone who manages this sort of thing for him. They didn't write you back, either. :)

      Nebulo

    9. Re:as Knuth told me when I was at his house by Anonymous Coward · · Score: 0

      Thanks for the clue, sharp guy.

    10. Re:as Knuth told me when I was at his house by davester666 · · Score: 1

      How? All the phones I've ever seen only take values....

      --
      Sleep your way to a whiter smile...date a dentist!
    11. Re:as Knuth told me when I was at his house by ghjm · · Score: 1

      Did you remember to reverse the order of all your words?

    12. Re:as Knuth told me when I was at his house by Anonymous Coward · · Score: 0

      I wrote him a real letter once. He didn't deign to reply to it either.

    13. Re:as Knuth told me when I was at his house by jschrod · · Score: 3, Interesting
      That's not quite right.

      He uses email; his secretary prints them out (after some selection) and forwards them. And he reacts to them. Well, at least, to some, if he knows you. Don is the most humble genius that I know, and I have always found him approachable in a way that is rare for other famous people.

      He also uses email (typically via his secretary, again) to organize trips. I also have direct emails from him when some new TeX developments irks him.

      --

      Joachim

      People don't write Manifestos any more -- what's going on in this world? [Frank Zappa]

    14. Re:as Knuth told me when I was at his house by JamesP · · Score: 1

      Let me guess, it was in HTML...

      Maybe you should talk to him

      --
      how long until /. fixes commenting on Chrome?
  2. holy shit? by Anonymous Coward · · Score: 0, Troll

    wow, my mind just got blown

  3. Crank it to 11 by MrEricSir · · Score: 4, Funny

    10 times faster? Yawn. Wake me up when it's 11 times faster.

    --
    There's no -1 for "I don't get it."
    1. Re:Crank it to 11 by PatPending · · Score: 5, Funny

      10 times faster? Yawn. Wake me up when it's 11 times faster.

      And wake me up when it's 1010 times faster.

      --
      What one fool can do, another can. (Ancient Simian Proverb)
    2. Re:Crank it to 11 by Anonymous Coward · · Score: 0

      I have one that goes to 12
      http://xkcd.com/670/

    3. Re:Crank it to 11 by Nadaka · · Score: 5, Funny

      That has to be the one of the better binary jokes around.

    4. Re:Crank it to 11 by AnonymousClown · · Score: 1

      10 times faster? Yawn. Wake me up when it's 11 times faster.

      Director: "Yeah but, why not just make each parts of the algorithm a little faster and that way 10x faster is faster than the old ten times faster."

      You: "But this goes up to 11 times faster."

      --
      RIP America

      July 4, 1776 - September 11, 2001

    5. Re:Crank it to 11 by morgan_greywolf · · Score: 1

      Wake up! It is 1010 times faster!

    6. Re:Crank it to 11 by Anonymous Coward · · Score: 0

      But does it go to 1011?

    7. Re:Crank it to 11 by noncaptusest · · Score: 1

      I don't get it. Am I sad or what? Joking ofc, or am I?

    8. Re:Crank it to 11 by PatPending · · Score: 1

      1010 = 12 in binary

      Sadly, no.

      --
      What one fool can do, another can. (Ancient Simian Proverb)
    9. Re:Crank it to 11 by Psychotria · · Score: 1

      1010 = 10 in binary

    10. Re:Crank it to 11 by Bigjeff5 · · Score: 1

      1010 = 12 in binary

      Somebody doesn't understand binary...

      --
      Security is mostly a superstition... Avoiding danger is no safer in the long run than outright exposure. - Helen Keller
    11. Re:Crank it to 11 by Like2Byte · · Score: 2, Funny

      10 times faster? Yawn. Wake me up when it's 11 times faster.

      And wake me up when it's 1010 times faster.

      I give that post an 0xA!

    12. Re:Crank it to 11 by Maglos · · Score: 1

      I still prefer, "there are 10 types of people in this world, those who get it and those who do not."

    13. Re:Crank it to 11 by Anonymous Coward · · Score: 0

      Well considering that up til now there were only 10 of them...

    14. Re:Crank it to 11 by Nebulo · · Score: 1

      That has to make the other one 10 of the better binary jokes around.

      Nebulo

    15. Re:Crank it to 11 by The+Bean · · Score: 1, Redundant

      There are only 10 types of people in the world, those who understand binary, and those who don't...

    16. Re:Crank it to 11 by SpaceLifeForm · · Score: 1

      Your post should be modded up +5 troll,
      because you certainly caught one.

      --
      You are being MICROattacked, from various angles, in a SOFT manner.
    17. Re:Crank it to 11 by ozmanjusri · · Score: 1

      So where do I find the other 1001 of them?

      --
      "I've got more toys than Teruhisa Kitahara."
    18. Re:Crank it to 11 by deniable · · Score: 2, Informative

      No, but they do understand octal.

    19. Re:Crank it to 11 by haploc · · Score: 1

      I bet it can go to 012!

    20. Re:Crank it to 11 by noidentity · · Score: 1

      10 times faster? Yawn. Wake me up when it's 11 times faster.

      How about something that's 11 times as fast?

    21. Re:Crank it to 11 by mariushm · · Score: 1

      It will only get interesting when it's OVER 9000 !

    22. Re:Crank it to 11 by psmears · · Score: 1

      1010 = 12 in binary

      Sadly, no.

      Octal fail!

    23. Re:Crank it to 11 by Anonymous Coward · · Score: 0

      It was not binary, but ternary...

    24. Re:Crank it to 11 by L4t3r4lu5 · · Score: 1

      I work in octal, and I certainly won't accept anything that isn't at least 12 times faster.

      --
      Finally had enough. Come see us over at https://soylentnews.org/
    25. Re:Crank it to 11 by tehcyder · · Score: 1

      That has to be the one of the better binary jokes around.

      Well, the other one's got a bit stale now.

      --
      To have a right to do a thing is not at all the same as to be right in doing it
    26. Re:Crank it to 11 by Splab · · Score: 1

      I hate that joke, if you understood binary then you'd know that 10 represents 4 states and thus 4 types of people. Yes 10binary = 2decimal, but still sucks.

    27. Re:Crank it to 11 by LinuxAndLube · · Score: 1

      1010 = 10 in binary

      But 10 in binary is 2 !

    28. Re:Crank it to 11 by thisisntme · · Score: 1

      if you understood binary then you'd know that 10 represents 4 states

      Ummm wtf? In what way does 10 represent 4 states?

    29. Re:Crank it to 11 by omnichad · · Score: 3, Funny

      I think they mean

      00

      01

      10

      11

      It represents 4 states the same way that 10 (decimal) represents 100 states. In other words, not at all (except for having 2 digits).

    30. Re:Crank it to 11 by guyminuslife · · Score: 1

      So where do I find the other 1001 of them?

      Well, I think you just proved that there's a class of people who understand binary but can't do subtraction.

      --
      I don't believe in time. It's a grand conspiracy designed to sell watches.
    31. Re:Crank it to 11 by Anonymous Coward · · Score: 0

      If they're very small states population-wise, with only a single representative each, and two of the 8 senators have resigned in disgrace after a scandal involving pages and/or callgirls, then 10 can represent 4 states.

      HTH, HAND

    32. Re:Crank it to 11 by Anonymous Coward · · Score: 0

      Stop the hate and educate!

      Restated for the hater:

      There are 1 types of people in the world, those who county binary states as opposed to translating binary into decimal, and those who don't.

    33. Re:Crank it to 11 by MikeBabcock · · Score: 1

      10 represents exactly one value in binary.

      Two digits of binary, 'nn' for argument, can represent up to four values, but 10 is still just one.

      Nomenclature, people.

      --
      - Michael T. Babcock (Yes, I blog)
    34. Re:Crank it to 11 by fbjon · · Score: 1

      +101 Funny!

      --
      True confidence comes not from realising you are as good as your peers, but that your peers are as bad as you are.
    35. Re:Crank it to 11 by General+Wesc · · Score: 1

      Does the decimal number 90 represent 100 states? Your absurd usage of numbers is self-defeating: if 10bin doesn't represent 'four states' rather than the cardinal number two, surely 11 does as well, in which case 10=11 and there are only three distinct states: 00, 01, and 10. I suspect under your system the other states would collapse as well.

  4. Nope, he didn't by siddesu · · Score: 5, Informative

    Knuth's analysis is valid in the framework of his assumptions, and what is described in the linked article has been known as "cache oblivious b-tree" for not so short time.

    1. Re:Nope, he didn't by SashaMan · · Score: 5, Insightful

      Mod parent up. There was a comment on the article that referenced cache oblivious algorithms, which was a new concept to me and very interesting. Basically, this set of algorithms assumes a memory hierarchy (e.g. fast ram vs slow disk) that is optimized to limit the number of times the slower memory is accessed. Importantly, cache oblivious algorithms are optimal REGARDLESS of the size of the cache. That's opposed to a cache aware algorithm, like a normal b-tree, where the size of each node is set according to the page size of the machine.

      A very helpful overview here from MIT Opencourseware: http://www.catonmat.net/blog/mit-introduction-to-algorithms-part-fourteen/

    2. Re:Nope, he didn't by lalena · · Score: 2, Interesting

      Yes, you are correct. I think the author could have just showed figures 5 & 6 and said obviously figure 6 is better and I would have gotten the point.
      Instead I had to read a bunch of text and timing charts before he simply showed what his improvement was. Yes, cache oblivious is worse, but that wasn't the problem Knuth was trying to solve. You could make further arguments that the paging system should group links by location AND popularity. You could move more popular links to the top of the tree so you don't have to traverse past the first page to find them. Also, I would think different applications would have different potential improvements. Algorithms for hosting links to news articles (where newer articles are more popular) might not work well with this algorithm when every newly inserted link ends up at the bottom of the tree.
      On the flip side, most people don't care. Unless you have many servers, it is cheaper to throw money at the problem in the form of physical RAM before you start thinking about problems like this.

    3. Re:Nope, he didn't by Darinbob · · Score: 4, Insightful

      Agreed. Very often these results get misused and misunderstood. Every operation has a cost, and you need to know what those costs are before you decide which one of those gets measured.

      For instance, it is common with sorting algorithms to measure (in Big-Oh notation) how many comparison operations there are. However these may not necessarily be very expensive relative to other operations; such as the cost of swapping two elements. If the elements are large structures and the comparison keys are integers, then you should be concerned about the number of copies. But if the elements are pointers to structures and the keys are long strings, then the concern will be with the number of comparisons.

      Almost every text book on algorithms you see is going to assume some sort of idealized computing device. In the real world there are multiple levels of memory speeds; caches up to virtual memory to disk. There are also other external factors that must be taken into account as well; for instance if you don't have enough memory, virtual or not, to hold all the data at once. Say you're sorting a database selection; or you're on a mainframe with limited memory space but reading customer data from tapes.

    4. Re:Nope, he didn't by Darinbob · · Score: 2, Interesting

      Much of this also depends on the relative size of the data elements compared to sizes of page or cache lines.

      For instance if the b-tree node is roughly the size of a page, the entire node must be read into memory at once from disk. Even reading a single byte of the record may necessitate reading the entire page. However this size will likely be much larger than a cache line. So you could have quite a lot of variance in performance based on how much of the structure you access; say scanning through the whole node versus just reading a few words at the top.

    5. Re:Nope, he didn't by jemfinch · · Score: 2, Insightful

      No, and no. The data structure described by Henning-Kamp is not a B-tree, but a heap. Additionally, it's cache-aware, not cache-oblivious.

    6. Re:Nope, he didn't by Sulphur · · Score: 1

      Are those European bees or African bees?

    7. Re:Nope, he didn't by fractoid · · Score: 1

      Laden or unlad-OHGODBEES yaarglh!

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
    8. Re:Nope, he didn't by coolgeek · · Score: 0, Troll

      Not to mention the author's frame of reference is totally invalid, because in the real world, we make sure we have so much RAM in our servers that virtual memory never becomes that large of a factor. So, bottom line, some nobody trolling for some fame on the back of one of our most respected predecessors.

      --

      cat /dev/null >sig
    9. Re:Nope, he didn't by NoOneInParticular · · Score: 1

      We're talking about a http cache here. When you've got enough RAM to cache the entire internet, please come back to us with this tired argument. BTW, the guy used this in a somewhat real-world setting where he replaced 10 squid servers with 3 using his algorithm.

    10. Re:Nope, he didn't by JasterBobaMereel · · Score: 3, Insightful

      Does it work : Yes

      Is there a better way : Yes

      Did it take 46 *years* for anyone to find a better way : yes

      If Knuth's mistakes take this long to spot then I still rate his code over most peoples

      --
      Puteulanus fenestra mortis
    11. Re:Nope, he didn't by yuhong · · Score: 5, Insightful

      Especially when virtual memory did not exist 46 years ago.

    12. Re:Nope, he didn't by yuhong · · Score: 1

      Actually I read that it did, but still was quite immature.

    13. Re:Nope, he didn't by mcvos · · Score: 1

      I think the theoretical possibility had been coined three years earlier.

    14. Re:Nope, he didn't by ThePhilips · · Score: 0, Troll

      Not to mention the author's frame of reference is totally invalid, because in the real world, we make sure we have so much RAM in our servers that virtual memory never becomes that large of a factor.

      You are wrong - about where he's wrong. The author essentially takes a very niche application, optimizes it and then goes to wildly extrapolate his finding on CS in general. That's where he's wrong.

      Lots of server applications (RDBMSs, HTTPDs) would love to get better use of VM and load all the junk once and serve it as if from memory. The problem is that in RTFA's niche application (very dumb cache) one doesn't have to take care for things like coherency or consistency, something most other applications are bound to provide out of box and what contributes lion share of their complexity. And yes, instead of increasing the applications complexity, we'd rather throw some buck at RAM and keep it simple instead.

      --
      All hope abandon ye who enter here.
    15. Re:Nope, he didn't by ThePhilips · · Score: 1

      MIX didn't have any VM. Not that VM is so much relevant to general CS. And it's not even about general CS: it is about computer and OS architecture. Even the RTFA's b-heap structure can be viewed as heap of heaps: main heap made of pages and sub-heaps inside of the every page. So much for novelty...

      --
      All hope abandon ye who enter here.
    16. Re:Nope, he didn't by mr+exploiter · · Score: 1

      Did it take 46 *years* for anyone to find a better way : yes

      Wrong: you must read this as what it is, an advertisement, the advantage of b-trees for in-disk operations has been known for a looooong time.

    17. Re:Nope, he didn't by azmodean+1 · · Score: 1

      Tiny nit, cache-oblivious algorithms are generally asymptotically optimal (some are actually optimal), which means they tend towards optimality, but an architecture-aware solution can be strictly better. As I say though this is a very tiny nit, only in the highest echelons of performance-critical applications should this be an issue.

      Specifically regarding the VM optimization the article is about, if your data structures/access patterns aren't aligned to pages you will generate "unnecessary" page faults. The VM system does not share the properties of cache that make that kind of optimization possible. As far as that is concerned I think the article is mostly correct, for optimal large-scale data processing, you have to be page-aware, which is exceedingly common in kernelspace (either BSD or Linux), but also exceedingly rare in userspace.

      Concerning his assertion that CS departments are ignoring physical realities of computing, I'm not as sure of. I specifically recall having the concepts he is talking about introduced to me in a data structures class (not specifically with regard to VM page size, but with regard to cache alignment and on-disk data representation, obviously it generalizes to VM behavior if your application is using it.) YMMV, which perhaps makes his point.

    18. Re:Nope, he didn't by azmodean+1 · · Score: 1

      The node must be = page size AND page aligned. If it is not both of these things you will often read two pages per node. This isn't just a restriction that says, "when you read from swap, you must read 4K at a time". The reality is that the data is partitioned into specific 4K chunks, and if your data structure is not aligned to that 4K partitioning scheme, you can read a trivial amount of data and cause not just one, but two page faults.
      Also you seem to have missed the entire point of the article, which is that once you've had a page fault, you want to maximize the amount of useful data you retrieve with that page. The point is that there IS practically no difference between faulting a page and reading a single word from it and faulting a page and reading all of it. The time to do the page fault in this case absolutely dwarfs the time spent processing the data retrieved in that page. The use of a cache-oblivious algorithm is orthogonal to page-aligning your data structure, which is what the article is about.

      Put another way, if your working set doesn't fit in ram, or more particularly if it is much larger than your available ram, you will get practiccally no benefit from using a cache-oblivious or cache-aware algorithm if you aren't also page-aligning your data, the disk access overheads (including swapping out OTHER memory) absolutely dwarfs any gain from micro-optimizations.

    19. Re:Nope, he didn't by Anonymous Coward · · Score: 0

      You should read up on your history. Start with MULTICS.

    20. Re:Nope, he didn't by sjames · · Score: 1

      Exactly. The people blindly applying Knuth to a machine that doesn't match Knuth's assumptions and making no adjustment for that got it wrong.

    21. Re:Nope, he didn't by Anonymous Coward · · Score: 0

      Especially when virtual memory did not exist 46 years ago.

      The idea existed. From TFA:

      In an article in the April 1961 of CACM, J. Fotheringham documented how the Atlas Computer at Manchester University separated the concept of an address from a memory location, which for all practical purposes marks the invention of VM (virtual memory)

  5. Knuth didn't get it wrong by gnasher719 · · Score: 4, Insightful

    You should have read a bit further to the bit with B-trees and B*-trees.

    1. Re:Knuth didn't get it wrong by wonderboss · · Score: 1
      Here! Here!

      And the slashdot entry is also wrong. The article doesn't say anything about "an off-by ten error in btrees". It doesn't talk about btrees except for a passing reference. It talks about heaps and heapsort.

      --
      more cowbell
    2. Re:Knuth didn't get it wrong by Anonymous Coward · · Score: 0

      B-trees or not B*-trees, that is the question.

    3. Re:Knuth didn't get it wrong by ImABanker · · Score: 5, Informative

      How does one get from, "I have not found a systematic flaw in the quality of Knuth et al.'s reasoning" to "Knuth Got it Wrong"?

    4. Re:Knuth didn't get it wrong by Anonymous Coward · · Score: 0

      Yes, because that article is about the optimization of heaps and not B-trees.

    5. Re:Knuth didn't get it wrong by Nimey · · Score: 1

      But then the post wouldn't be sensational, wouldn't get as many views, and would leave you with a positive view of Slashdot editors.

      --
      Hail Eris, full of mischief...

      E pluribus sanguinem
    6. Re:Knuth didn't get it wrong by Anonymous Coward · · Score: 0

      "Hear, hear!" -- It's not: "Here I am, and I agree!" It's more like: "Listen to this guy, he's talkin' sense."

    7. Re:Knuth didn't get it wrong by Bigjeff5 · · Score: 4, Funny

      Laziness?

      Come on, it's Slashdot!

      --
      Security is mostly a superstition... Avoiding danger is no safer in the long run than outright exposure. - Helen Keller
    8. Re:Knuth didn't get it wrong by Anonymous Coward · · Score: 1, Informative

      You start with k, and follow with dawson.

    9. Re:Knuth didn't get it wrong by Jedi+Alec · · Score: 1

      And the slashdot entry is also wrong. The article doesn't say anything about "an off-by ten error in btrees". It doesn't talk about btrees except for a passing reference. It talks about heaps and heapsort.

      Well, yeah, but completely mangling whatever is in the article to sound as inflammatory as possible has been the /. way for at least 5 years or so now.

      Let me put it this way, if I ever see a Slashdot topic with the title "No reason to believe world will end tomorrow" that'll truly push the panic buttons.

      --

      People replying to my sig annoy me. That's why I change it all the time.
    10. Re:Knuth didn't get it wrong by Anonymous Coward · · Score: 0

      How does one get from, "I have not found a systematic flaw in the quality of Knuth et al.'s reasoning" to "Knuth Got it Wrong"?

      That bold jump in the level of assertiveness of the headline is based on another type of scientific measurement: the latter headline has a 50-60% more click-through rate.

      This metric of truth, albeit not universally accepted amongst scientists, is exceedingly popular amongst news site editors and advertisers. Our Slashdot overlords have bowed to massive industry pressure here, so to speak.

    11. Re:Knuth didn't get it wrong by tgd · · Score: 1

      When you are paid in ad impressions, views matters, not accuracy.

      Which of those two statements is going to get people on Slashdot to read it?

    12. Re:Knuth didn't get it wrong by Anonymous Coward · · Score: 0

      next up "i'm in yr btrees doin it rite" over a lolcat

  6. don't use swap, doofs by conspirator57 · · Score: 4, Insightful

    article summary:

    "disk is slower than RAM. some doofs don't realize their system is swapping. ergo algorithm is bad."

    throw in 'Knuth is wrong' to generate page hits.
    ???
    profit.

    non-sensationalized takeaway: "remember swap is slow; try not to use it."

    --
    "If still these truths be held to be
    Self evident."
    -Edna St. Vincent Millay
    1. Re:don't use swap, doofs by TENTH+SHOW+JAM · · Score: 1

      non-sensationalized takeaway: "remember swap is slow; try not to use it."

      Not really. Closer to "Remember, swap is slow. Think about how you use it."

      --
      A sig is placed here
      To display how futile
      English Haiku is
    2. Re:don't use swap, doofs by maraist · · Score: 2, Insightful

      Did you read the article? Not that it's terribly innovative or anything, but he's not saying anything about swap is slow.. He's saying when you need to page to disk (e.g. a database or disk-spilling cache), don't use traditional B-Tree's or B+Tree's which tend to only store a single level in a memory-page / disk-page. This causes Log(n) disk-lookups to find the leaf-node (where all B+Tree data lives, and half of B-Tree data lives). Instead store multiple levels of the tree in a contiguous mem/disk page. It's a relatively simple re-organization, and I don't think he's scaling out as well as he's suggesting (when you get to 1B + records - you're not going to get a large number of the 20 level lookups in a single vertical slice).

      --
      -Michael
    3. Re:don't use swap, doofs by gmack · · Score: 1

      More like: swap is slow. When you are using it try to make things you need to access at the same time closer together to minimize reads.

    4. Re:don't use swap, doofs by Anonymous Coward · · Score: 0

      ... He's saying when you need to page to disk (e.g. swap)...

    5. Re:don't use swap, doofs by EvilIdler · · Score: 1

      "doofs"? You should look up some information on the author :)

    6. Re:don't use swap, doofs by maraist · · Score: 1

      You realize that mmap is essentially programmatic swap right? That if you do random file-seeks on a large (hundred+ gig) file, that you're relying on the file-system cache 'swapping' (though not to a swap-file). And that both of these are very similar to explicit paginated disk-in / disk-out with the O_DIRECT flag.

      I've programmed app-level caches, and am very aware of the memory/disk trade-offs, so I completely understand where he's coming from (even though I don't know the details of his tool).

      What I think you're getting at is an app that assumes it can just use 300gig of RAM, and thus swap the whole OS to disk (e.g. /dev/sda2 the swap partition). Maybe he did it and maybe he didn't, but I can certainly see how to apply his algorithm to explicitly swapped RAM (that doesn't hit swap). And I suspect that the performance characteristics would be similar (except for the responsiveness of other apps on the machine). Though for non O_DIRECT file-cache based super-sized apps, you'd have similar peer-app stalls.

      --
      -Michael
    7. Re:don't use swap, doofs by fractoid · · Score: 1

      Instead store multiple levels of the tree in a contiguous mem/disk page.

      I seem to recall a chapter in a programming book that I read maybe 15 years ago, talking about 'locality of reference' for optimisation. It was the same concept as this: Structure your memory usage to keep data that are accessed together, stored together. Then, whatever caching mechanism is in place will be able to spend less time paging (or spread the paging out over a larger number of CPU cycles) and thus have better throughput.

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
    8. Re:don't use swap, doofs by borgboy · · Score: 2, Informative

      In no way whatsoever did he say 'remember swap is slow; try not to use it.'

      That's as wrong as the idiotic summary.

      Here's a relevant quote:

      A 300-GB backing store, memory mapped on a machine with no more than 16 GB of RAM, is quite typical. The user paid for 64 bits of address space, and I am not afraid to use it.

      The article is about redesigning binary heaps to account for non-linear access times between nodes due to swap. This point is critical. He's NOT avoiding swap, he's planning for it.

      --
      meh.
    9. Re:don't use swap, doofs by dominious · · Score: 2, Funny

      non-sensationalized takeaway: "remember swap is slow; try not to use it."

      Not really. Closer to "Remember, swap is slow. Think about how you use it."

      "Your response has exactly the same length as the parent's quote. Interesting"

    10. Re:don't use swap, doofs by conspirator57 · · Score: 1

      yeah, it was wrong in that it wasn't purely a distillation of the article, but rather a synthesis with my own experiences. i should have accurately represented it as such.

      i was terse because i was miffed at his hubris to assume that no one's been working in filesystem, swap, and application IO tuning for the last 40 years or so, something i've actually done (but of course, not for 40 years).

      everyone makes choices on which abstractions to use and which to discard for performance/cost purposes. the author is merely asserting (without actually stating it) that enough people have the same use case of 16:300 ram:disk that it is worth discarding the abstraction that says that the application should just assume that everything it writes to/reads from is ram. OK, but this is hardly revolutionary. Nor is it universally correct for all cost/performance tradeoff decisions.

      Mmap isn't always the correct choice either. In fact, using mmap is the thing that provides the abstraction that your disk is memory for you, so you can hardly blame application programmers for using the abstraction naively, especially when they may have no idea what hardware decisions have been made. maybe using raw file IO and keeping your accesses to multiples of the system IO size would be better. Of course if you do that you might also want to pay attention to stripe sizes if you're striping your jbod scratch. make them an even multiple (or better, a power of 2 multiple) of your system IO size as well.

      also, xdd's pretty fly for benchmarking i hear.

      http://www.ioperformance.com/

      And personally i prefer to maximize RAM size and IO bandwidth over processor speed for most applications.

      http://www.newegg.com/Product/ProductList.aspx?Submit=ENE&N=2010200302+1072521815&QksAutoSuggestion=&ShowDeactivatedMark=False&Configurator=&Subcategory=302&description=&Ntk=&CFG=&SpeTabStoreType=&srchInDesc=

      --
      "If still these truths be held to be
      Self evident."
      -Edna St. Vincent Millay
    11. Re:don't use swap, doofs by borgboy · · Score: 1

      ...and now I find myself agreeing with pretty much everything you just said.

      When performance counts, there is absolutely, positively zero substitute for understanding the workload at hand and the hardware it will run on.

      --
      meh.
    12. Re:don't use swap, doofs by sjames · · Score: 1

      More like swap is slow, use it wisely. The entire premise of TFA was how to arrange your data structure so that a search generates as few faults as possible. If your data will fit neatly into RAM, the algo in TFA would lose.

      The non-sensationalized take-away is that if your data is larger than RAM, re-arrange your algorithm to minimize page faults rather than blindly following Knuth. Alternatively, remember: Knuth assumed all memory was in-core.

  7. already proposed 40 years ago... by godrik · · Score: 1

    You mean people are implementing heap like that ?

    That would indeed be stupid. People have been using B-tree http://en.wikipedia.org/wiki/B-tree instead of Binary search trees for the cache access (or sequential disk IO) reason forever.

    More recently we have been talking about cache oblivious and cache aware algorithm : http://en.wikipedia.org/wiki/Cache-oblivious_algorithm

    I should write an article about Z-order and be on the first page of slashdot...

    1. Re:already proposed 40 years ago... by AnonymousClown · · Score: 1

      I should write an article about Z-order and be on the first page of slashdot...

      Don't forget the pretty colorful graphs!

      --
      RIP America

      July 4, 1776 - September 11, 2001

  8. Credit where credit is due... by Anonymous Coward · · Score: 5, Informative
    1. Re:Credit where credit is due... by Anonymous Coward · · Score: 0

      There was an old joke about a guy did a telephone interview with Paul McCartney:
      "Who are you? Why are you calling at this hour?"

  9. Journaling Filesystems by KriKit · · Score: 1

    Don't Journaled filesystems themselves use b-trees? Does this mean they could be much faster in theory?

    1. Re:Journaling Filesystems by KriKit · · Score: 2, Interesting

      If were talking about swap then nevermind, nothing you can do there. The filesystem is the swap.

    2. Re:Journaling Filesystems by Guy+Harris · · Score: 1

      Don't Journaled filesystems themselves use b-trees?

      File systems that use b-trees use b-trees; file systems that don't use b-trees don't use b-trees. Both types of file systems can be journaled or not journaled.

    3. Re:Journaling Filesystems by DavidR1991 · · Score: 2, Funny

      What is this? The freaking tautology hour?

    4. Re:Journaling Filesystems by JamesP · · Score: 1

      Maybe they're playing bad cop, tautological cop

      --
      how long until /. fixes commenting on Chrome?
  10. Agreed by eldavojohn · · Score: 5, Insightful

    Knuth's analysis is valid in the framework of his assumptions, and what is described in the linked article has been known as "cache oblivious b-tree" for not so short time.

    Yeah, using this logic, once quantum computers get to the point of solving general problems there's going to be an awful lot of people who "got it wrong" because their algorithms do not apply in a quantum computer. Advancements in technology causing algorithms & data structures to be tweaked means the original person who thought them up "got it wrong"? Ridiculous.

    "Oh, RSA was brilliant. But they got it wrong. You see, they failed to account for xanxinglydiumapping in 2056 computers. Poor stupid wrong bastards."

    --
    My work here is dung.
    1. Re:Agreed by buchner.johannes · · Score: 1

      He also literally says: "So, yes, Knuth and all the other CS dudes had their math figured out right. "
      A bit odd language for a paper ... does that come from BSD mailing lists?
      Why does this page have comments? To mock xkcd? Well, I guess it isn't a paper. WTH is it?

      Anyway, I think the argument is right as a whole: Algorithm analysis does also have to respect the factors that the O-notation hides (memory and cpuwise), and the way memory works. But I don't know, my Data Structures and Algorithms teacher was perfectly aware of this ...

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    2. Re:Agreed by jonadab · · Score: 3, Interesting

      I think "got it wrong" in the past tense is a little harsh, but I would say that a LOT of stuff in Knuth is wrong today, or at least terribly obsolete. It's not useless to be aware of, but you don't want to assume that everything is today still exactly the way Knuth described it in the digital stone age.

      I mean, just for example, Knuth spends whole chapters talking about sorting algorithms. Almost all modern programmers don't have any use for that stuff, because re-implementing sort in your application code is pointless and counterproductive. The built-in sort provided by any modern language is optimized at a lower level and will handily beat the pants off anything you can do. Heck, even the Schwartzian Transform is built in to most modern languages these days.

      Okay, sure, the guys who build low-level tools (compilers and system libraries and such) still need to know about sorting routines. What percentage of the programmer population is that? 0.1%? And even there, Knuth is somewhat obsolete, because (among other things) the stuff you're sorting is almost certainly stored in high-level cross-platform data structures, not some flat array of machine integers. I mean, it's still true that you probably don't want to code a bubble sort, but that's not exactly a profound revelation.

      --
      Cut that out, or I will ship you to Norilsk in a box.
    3. Re:Agreed by lennier · · Score: 1

      "Oh, RSA was brilliant. But they got it wrong. You see, they failed to account for xanxinglydiumapping in 2056 computers. Poor stupid wrong bastards."

      You say that now, but just wait until the Googapple Braindroid Psi-Spam Wars of 2073 melt the Moon. Then you'll be all 'well of course they should have protected against inertial vs gravitational mass attacks, every first-year Quantum Relativistic Graphics Acceleration student knows THAT'.

      --
      You are not a brain: http://books.google.com/books?id=2oV61CeDx-YC
    4. Re:Agreed by Nicolay77 · · Score: 1

      PHP does not have an stable sort.

      In fact, stable sorts are discouraged by most languages, by virtue of not being as fast as other sorts.

      But when you need to apply several sorts to the same data (and it is faster to do it in PHP than in the DB layer), you need a stable sort.

      --
      We are Turing O-Machines. The Oracle is out there.
    5. Re:Agreed by jonadab · · Score: 1

      > PHP does not have an stable sort.

      PHP doesn't have a lot of things.

      Even in PHP, though, you're not going to code a stable sort by going to Knuth and picking out one of his algorithms. You're going to do basically a Schwartzian Transform, using the original position index as the last sort criterion, so you can take advantage of the built-in (unstable) sort. It'll perform better than a quicksort or heapsort or whatever that you code up from scratch.

      --
      Cut that out, or I will ship you to Norilsk in a box.
  11. Theoretical performance vs real-world performance by InsertWittyNameHere · · Score: 2, Insightful

    Yes it's true. In some real-world applications an algorithm encounters it's worst case running time more than the predicted theoretical average case running time. This is where case by case optimizations come into play.

    Knuth never claimed the algorithm was the best choice in YOUR particular case. Don't drag his name through your sensational mud for the sake of your slashvertisement.

  12. Knuth didn't get anything wrong by jfengel · · Score: 5, Insightful

    There isn't any "off by ten error", and this isn't telling us anything we don't already know (in CS terms): implementation on an actual computer can be different in performance from an abstract machine.

    What the author is saying (quite well) is that the virtual memory performance amounts to cache misses, which cause extra performance overhead. He found a case where it was significant and got a 10x speedup in his particular application.

    The article is a little over-zealous its characterization, though it's careful to note that this is not actually a theoretical novelty. The summary, on the other hand, bastardizes and exaggerates it.

    The article is interesting, and worth reading, but if you RTFS without RTFA you'll be dumber than you were before. Thanks, kdawson.

    1. Re:Knuth didn't get anything wrong by juuri · · Score: 1

      What's troubling to me about this article is it reads like this guy hasn't been paying attention for quite a while.

      Squid is his use case to beat? Has he been in any high performance app stack in the past five years?

      Squid... really?

      --
      --- I do not moderate.
    2. Re:Knuth didn't get anything wrong by Lord+Crc · · Score: 2, Interesting

      Squid is his use case to beat? Has he been in any high performance app stack in the past five years?

      Squid... really?

      Considering Varnish was written due primarily to the lacking performance of Squid, I don't see why this is so bad?

    3. Re:Knuth didn't get anything wrong by Cirvam · · Score: 2, Interesting

      Other then varnish and squid what caching reverse proxy software is there? It looks like Nginx added caching to their core recently, although I'm not exactly sure if its intended to act in the same capacity as squid and varnish or to be more like mod_cache for lighttpd. I guess you could use apache and mod_proxy but that's not exactly high performance. I know my employer looked at the various offerings and we ended up writing our own on top of a webserver called OKWS.

    4. Re:Knuth didn't get anything wrong by Pedrito · · Score: 0

      The article is a little over-zealous its characterization, though it's careful to note that this is not actually a theoretical novelty. The summary, on the other hand, bastardizes and exaggerates it.

      Not to mention, but what a conceited prick the author is as well.

      One of the main reasons I accepted the Varnish proposal was to show how to write a high-performance server program... Because, not to mince words, the majority of you are doing that wrong.

      Oh, please do mince words. Why don't you tell all of us, your sad little children, how we should be doing things, oh master. Clearly you're the shit! Get over yourself already.

    5. Re:Knuth didn't get anything wrong by godless+dave · · Score: 1

      The article is a little over-zealous its characterization, though it's careful to note that this is not actually a theoretical novelty. The summary, on the other hand, bastardizes and exaggerates it.

      Welcome to Slashdot!

      --
      "If it's real, then it gets more interesting the closer you examine it. If it's not real, just the opposite is true." -
    6. Re:Knuth didn't get anything wrong by steveha · · Score: 1

      My favorite quotes from the article:

      Would you believe me if I claimed that an algorithm that has been on the books as "optimal" for 46 years, which has been analyzed in excruciating detail by geniuses like Knuth and taught in all computer science courses in the world, can be optimized to run 10 times faster?

      It would of course be unjust and unreasonable to blame Williams for not realizing that Atlas had invalidated one of the tacit assumptions of his algorithm: only hindsight makes that observation possible. The fact is, however, 46 years later most CS-educated professionals still ignore VM as a matter of routine. This is an embarrassment for CS as a discipline and profession, not to mention wasting enormous amounts of hardware and electricity.

      I can tell you that they never covered any of this stuff when I was in college. I learned about it by reading articles like this one.

      P.S. He never claimed that Knuth was "wrong". In fact, when the data set fits purely in RAM and your server isn't swapping, the algorithm's original assumptions are valid and it is in fact fastest. (And there are numbers in TFA explaining exactly this!) But he is absolutely correct that in real-world applications, swapping matters a lot. His algorithm isn't much slower in the non-swapping case, and can be 10x faster or more in the swapping case.

      He did use phrases like "You're doing it wrong", which will drive some readers nuts. But I view it as just his way of making the article more interesting. This material could have been very dry and boring; as written, it's a fun article that still communicates the material well.

      The article is interesting, and worth reading, but if you RTFS without RTFA you'll be dumber than you were before. Thanks, kdawson.

      I agree on all points.

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    7. Re:Knuth didn't get anything wrong by gnud · · Score: 1

      TFA writes about how the norwegian newspaper VG replaced 10 squid machines with 3 varnish machines and got much better performance. That switch was done 5 or so years ago, before varnish was first released as open source. He's not writing about beating squid _now_.

  13. Cache behavior is hard and not portable by MagikSlinger · · Score: 1

    I am sympathetic with his argument, but trying to figure out the best algorithm for a given OS and hardware combo is very difficult and usually not portable.

    --
    The bitter lessons of a veteran coder: http://bitterprogrammer.blogspot.com
    1. Re:Cache behavior is hard and not portable by DragonWriter · · Score: 1

      I am sympathetic with his argument, but trying to figure out the best algorithm for a given OS and hardware combo is very difficult and usually not portable.

      Assuming that the number of actual caching strategies is smaller than the number of hardware and OS combos (which it would seem likely to be, since at least some of those should share caching strategies), what is really needed is analysis of the determinants of algorithm performance that take into account different caching strategies. That's still difficult compared to simple ideal assumptions like constant memory access cost, but simple metrics that don't capture real world behavior well are of limited utility.

    2. Re:Cache behavior is hard and not portable by owlstead · · Score: 1

      If you make sure that you require less pages to do something, you will generate less page faults. I would think that this fact is rather universal. Of course, you can go further by tweaking the parameters in such a way that they run well on a specific processor.

    3. Re:Cache behavior is hard and not portable by MagikSlinger · · Score: 1

      I suppose, but have all modern OS's finally agreed on a universal LRU algorithm, or do we still have "clever" algorithms that try to figure out if the application is user-centric or server-centric then changes the page expiry accordingly?

      --
      The bitter lessons of a veteran coder: http://bitterprogrammer.blogspot.com
    4. Re:Cache behavior is hard and not portable by Nebulo · · Score: 1

      Isn't that a big part of what he's saying - that some algorithms should be written in a non-portable way so they maximize performance? For example, a different system might implement VM in a way that eliminates his performance gains.

      Nebulo

    5. Re:Cache behavior is hard and not portable by azmodean+1 · · Score: 1

      1. I don't think you can do this kind of optimization in a portable way period, POSIX might pretend you can, but I doubt the implementations are consistent enough to reliably deliver.
      2. It's 4K, that's the page size that everyone has used for about 10 years now (of course it's finally changing now, bwahahaha).
      2a. Unless you mean page size for non-x86 hardware, in which case portability? Bwahahaha.

      But seriously, the algorithm is going to be the same, though the data structures and implementation might need a few tweaks here and there, that's what we get paid for, right?

  14. The lengths people will go to for $5 by mysidia · · Score: 0

    I think you only get it if you find an actual bug in Knuth's software though :)

  15. Re:Theoretical performance vs real-world performan by DragonWriter · · Score: 5, Informative

    Yes it's true. In some real-world applications an algorithm encounters it's worst case running time more than the predicted theoretical average case running time.

    That's actually not the issue.

    The issue is that in the real world, the assumptions underlying the calculation of algorithmic complexity may not hold. For instance, Knuth's analysis that the author of the article here holds to be misleading (not, as the Slashdot title suggests, "wrong") calculates the complexity based on the assumption of ideal random access memory, that is, memory for which all accesses are equal cost.

    In real-world computers using caches (as pretty much all real-world computers do, often at many different levels) that assumption does not hold -- access to some parts of the memory address space are much more expensive than accesses to other parts of the address space, and which parts of the address space are expensive changes over time (and how it changes over time potentially depends on the caching strategy used at every level lower than the level at which the algorithm is implemented.)

    This means that algorithms in the real world can scale worse than their theoretical "worst-case", if that theoretical worst-case scaling is based on the assumption of constant memory access cost, since that assumption does not hold in the real world.

  16. news at 11 by inkyblue2 · · Score: 3, Insightful

    Algorithm revised in light of real-world performance constraints! Read all about it!

    Seriously, we just rewrote a tree (that runs in a high traffic serving environment) this month at work because it wasn't streamlined just right to take full advantage of the underlying architecture. No one will write a paper about it.

    Also, hey kids, profile your code.

    1. Re:news at 11 by Michael+Kristopeit · · Score: 1

      we just rewrote a tree (that runs in a high traffic serving environment) this month at work because it wasn't streamlined just right to take full advantage of the underlying architecture. No one will write a paper about it.

      because you didn't want to admit that you stored the tree as folders and files on a FAT32 disk on windows 98?

  17. Ow my eyes by Anonymous Coward · · Score: 1, Insightful

    R-G colorblindness makes it near impossible to distinguish the graphs from each other.

    1. Re:Ow my eyes by Tubal-Cain · · Score: 1

      "Binary heap" start out highest line on the left in figures 1-4.

  18. Are you serious? Do you even know who phk is? by Anonymous Coward · · Score: 3, Informative

    Poul-Henning is definitely not a "doof". He's single-handedly responsible for a huge amount of the FreeBSD kernel. Yes, this is the same FreeBSD that powers Yahoo!, that provided a significant portion of Mac OS X, and runs hundreds of thousands of businesses world-wide.

    To suggest that phk doesn't know what he's talking about is absurd. He's one of the top three UNIX gurus in the entire world. In fact, the Internet today is what it is thanks to his hard work and dedication.

    1. Re:Are you serious? Do you even know who phk is? by MightyMartian · · Score: 3, Insightful

      I don't think anyone accused him of not knowing what he's talking about. He's been accused of using an extremely hyperbolic headline to draw readers. Besides, what he's saying isn't exactly brand new.

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    2. Re:Are you serious? Do you even know who phk is? by McNihil · · Score: 4, Insightful

      To place algorithm theory in the same space as implementation is just plain wrong... and the article does say that in a better way than kdawson's sensationalist header.

      The implementation of a particular algorithm on specific hardware is more inline with resource economy than anything else and to subject comparison to the theoretical implementation is just ludicrous.

      For instance one could with simple means device a unit where only bubble-sort would be possible because of the massive overhead of qsort on said machine. This is trivial... for instance Casio Fx180 calculator.

    3. Re:Are you serious? Do you even know who phk is? by oldhack · · Score: 1

      Yeah, well, it worked - we responded, eh. kdawson, you bastard.

      --
      Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
    4. Re:Are you serious? Do you even know who phk is? by davecb · · Score: 1

      Hey, blame me, not kdawson! We both know who phk is.

      --dave (with tongue firmly in cheek) c-b

      --
      davecb@spamcop.net
    5. Re:Are you serious? Do you even know who phk is? by fractoid · · Score: 1

      It's not hyperbolic at all. phk is 100% correct, like usual. Knuth's estimates have been shown to be incorrect. In case you didn't catch it, that's what science is all about. Knuth posed his theory and his conclusions, and phk showed how they were wrong.

      Actually, Knuth posted his assumptions, theory and conclusions, and phk showed that some of the assumptions no longer hold true for physical hardware.

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
    6. Re:Are you serious? Do you even know who phk is? by ugen · · Score: 1

      That's PHK. You should have seen him 15 years ago in the FreeBSD core. He's a very smart developer but even more so he's very adept at blowing his own horn.

    7. Re:Are you serious? Do you even know who phk is? by name*censored* · · Score: 1

      With this level of reading comprehension, you must be in serious contention for the position of slashdot editor. No-one called Poul-Henning Kamp a doof. GP was saying that Poul-Henning Kamp was calling OTHER people doofs (implicit/paraphrase), as indicated by preceding "article summary" and the quotation marks.

      (On-topic:) This article headline was nicked from a reddit thread from yesterday (Poul-Henning Kamp has commented on this thread; or at least someone claiming to be him has).

      It would have been nice if the submitter/editors here had read the article instead of re-phrasing the more-accurate "You're doing it wrong" headline. Poul-Henning Kemp is expressing his exasperation at the fact that no-one has noticed this optimisation technique in the ~40 years that it's been valid, and attributes it to a failure in the programing culture and programming education. conspirator57's summary may be a little ruder than the article (which is astonishingly un-antagonistic), but conciseness always sacrifices pleasantries.

      --
      Commodore64_love: I don't comprehend people who're so frightened of death that they'll bankrupt themselves to stay alive
    8. Re:Are you serious? Do you even know who phk is? by ClosedSource · · Score: 1

      "He's one of the top three UNIX gurus in the entire world. In fact, the Internet today is what it is thanks to his hard work and dedication."

      I wasn't aware that UNIX guruism played such a key role in the Internet. I always thought it was stuff like Ethernet and TCP/IP.

    9. Re:Are you serious? Do you even know who phk is? by Anonymous Coward · · Score: 0

      OS X doesn't use the FreeBSD kernel.

    10. Re:Are you serious? Do you even know who phk is? by noidentity · · Score: 1

      He's the guy who pushes the program bank on the stack, right? There's no Ms. plk, though, so you have to use your pet, rtl.

    11. Re:Are you serious? Do you even know who phk is? by jopsen · · Score: 1

      I don't think he choose the slashdot headline...

    12. Re:Are you serious? Do you even know who phk is? by Anonymous Coward · · Score: 0

      TCP/IP was first implemented in BSD, and it was the availability of TCP/IP in BSD that drove the popularity of TCP/IP over the then officially endorsed OSI stack.

    13. Re:Are you serious? Do you even know who phk is? by ClosedSource · · Score: 1

      I think you're confusing BSD sockets with TCP/IP. You can have sockets without TCP/IP and you can have TCP/IP without sockets.

    14. Re:Are you serious? Do you even know who phk is? by Anonymous Coward · · Score: 0

      Poul-Henning Kemp is expressing his exasperation at the fact that no-one has noticed this optimisation technique in the ~40 years that it's been valid, and attributes it to a failure in the programing culture and programming education.

      Except it has been noticed, so the article could be better summarised as "Poul-Henning Kamp does not pay attention to the literature".

    15. Re:Are you serious? Do you even know who phk is? by Anonymous Coward · · Score: 0

      http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2936, the man is certainly not a doof but embedding a network accessible C compiler into Varnish and then allowing Varnish to be remotely reconfigured to run code injected into the C compiler with root privileges, all without authentication suggests that he does have off days.

    16. Re:Are you serious? Do you even know who phk is? by Anonymous Coward · · Score: 0

      He did also think it was wise to embed a C compiler into Varnish in such a way that C code could be injected into Varnish without credentials over the network and made to run with root privileges, and then argued that the reported flaw was fundamentally pointless: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2936

  19. Why trust the OS? by michaelmalak · · Score: 4, Interesting

    I'm not sure what the advantages are of dancing around with the OS's virtual memory system. If it were me, I would detect the amount of physical memory available, allocate 80% of it, lock it into physical memory and manage the paging myself. It would be portable, not subject to changes in the VM algorithm by the OS authors, and easier to directly monitor and improve performance. But that's just me.

    1. Re:Why trust the OS? by Anonymous Coward · · Score: 1, Funny

      Do you really need 3277MB of my RAM?

      Firefox 1.0 programmer I assume... :p

    2. Re:Why trust the OS? by Anonymous Coward · · Score: 2, Insightful

      Then someone starts two copies of your program and you lock 160% of available memory

    3. Re:Why trust the OS? by Anonymous Coward · · Score: 2, Interesting

      Why is this funny? Almost all DBMS kernels do it -- they manage physical memory and disk blocks themselves. More to the point, Dr. Kamp is glossing over the fact that one doesn't use in-memory data structures where data my reside on disk.

      In this case, the suitable data structure is any variation of B+Tree, which actually contains children of a node in one memory page and when there is no more room in that page a page split happens. He used the wrong D/S to begin with, concludes Knuth was wrong and finally ends up implementing Knuh's B+Tree.

    4. Re:Why trust the OS? by Chandon+Seldon · · Score: 1

      Very simply, because the OS developers are usually pretty smart and when you try to outsmart them and fail you look like a tool. And you're going to fail. If I knew that everyone who I posted a response like this would pay up, I'd bet you $1k that you'd fail and make mad cash.

      --
      -- The act of censorship is always worse than whatever is being censored. Always.
    5. Re:Why trust the OS? by Anonymous Coward · · Score: 0

      I'm not sure what the advantages are of dancing around with the OS's virtual memory system. If it were me, I would detect the amount of physical memory available, allocate 80% of it, lock it into physical memory and manage the paging myself. It would be portable [...]

      LOL, portable. Yeah, never mind memory overcommit strategies, the portability of "80%" itself, variable speeds of physical memory (i.e. NUMA), "managing" the paging (i.e fun queueing commands to hardware with all kinds of volume managers, RAID arrays, etc).

      not subject to changes in the VM algorithm by the OS authors, and easier to directly monitor and improve performance. But that's just me.

      LOL, easier to directly monitor and improve performance. CPU-specific performance counters, kernel process scheduling impact, the effect of starving the VM subsystem for the rest of the processes.

      You don't know what you're talking about. Why is this +5?

    6. Re:Why trust the OS? by npsimons · · Score: 1

      I'm not sure what the advantages are of dancing around with the OS's virtual memory system. If it were me, I would detect the amount of physical memory available, allocate 80% of it, lock it into physical memory and manage the paging myself. It would be portable, not subject to changes in the VM algorithm by the OS authors, and easier to directly monitor and improve performance. But that's just me.

      . . . and maybe you do know better than the OS authors; who knows, you may have actually implemented a few OSes or bare metal apps yourself. In the case of a system where you need that kind of control to hit benchmarks (eg, embedded real-time), this might be reasonable, or you'd probably just code it to the bare metal. But in most other cases, you should really try to look at how the OS is configured first and save yourself a lot of time; the option to tune RAM+swap and allocation schemes are probably already there. You might *think* you know better than the OS authors, but I doubt your app has had (or will ever have) the number of test cases thrown against it that any popular modern OS has. Those test cases most likely include something similar to your resource hungry app that should really be running on a dedicated machine, and not with the default multitasking options if you are using a general purpose OS at all. I've always maintained that any decent programmer is also a decent sysadmin who knows what his/or her operating system (and other abstraction layers) are doing, and how to change them. Otherwise, you're just some wanker badmouthing people who have put a lot of effort into making their code flexible and adaptable.

    7. Re:Why trust the OS? by Anonymous Coward · · Score: 0

      Then you are among the many who are getting it wrong.

      First of all, that leaves you responsible for swapping. Remember, this is about data sets that are far too large to fit in RAM at once (hundereds of gigabytes, in the author's example). You have to keep track of what's still being used, and decide when to move some data to disk or back. It leaves you responsible for keeping the disk copy and any in-memory copy in sync. This is EXACTLY the kind of problem modern operating systems were designed to handle, and they are very good at it. The VM system alone in a typical OS likely represents more development work than your entire application - you'd be a bloody idiot not to take advantage of it.

      Second problem - the assumption that your program is the only one on the machine (or the only one that matters). That rarely happens. Applications that take this approach usually can't be installed together on a single machine, because they end up fighting each other for resources (like Exchange or Microsoft's SQL Server). They usually can't even be installed with any other software - trying to use the machine for anything else will cause heavy swapping. However, if the applications let the OS handle memory allocation on their behalf, they would be able to coexist just fine - the OS would keep frequently / recently used data for all applications in memory. It will also automatically balance between them based on use.

      Seriously - modern operating systems are really good at memory management. Just let them get on with it. If you roll your own, you're almost certainly going to do a worse job of it than the operating system.

    8. Re:Why trust the OS? by bored · · Score: 1

      if it were me, I would detect the amount of physical memory available, allocate 80% of it, lock it into physical memory and manage the paging myself.

      Are you serious? You can honestly say that your monitoring each pages hit counts and swapping out only the pages with the lowest usage, and your not affecting anything else on the machine? What a load of baloney, just map the whole thing (like the author of the article is talking about) and let the OS paging algorithms make global decisions about the amount of ram and the consumption of the rest of the machine. That way when your on a machine with 64G of ram, your not leaving 12G of it unused, or when your on a 128M machine, crashing because you cannot get 80%.

    9. Re:Why trust the OS? by Anonymous Coward · · Score: 0

      Like squid does and which varnish outperforms...

    10. Re:Why trust the OS? by jimicus · · Score: 1

      And you would immediately incur the wrath of sysadmins like me who have dealt with RDBMSs that assume the database would be all that ever runs on the system.

      (Hint: That's probably true for any modern database in any sensibly-sized organisation, but it's not necessarily true if you're running some clapped-out legacy database which doesn't speak SQL and you need to install on the same hardware some sort of layer to get it to talk to the new systems. In fifteen years' time it's entirely possible that today's database will be the clapped-out legacy which needs another layer installed in order to get it talking with newer software)

    11. Re:Why trust the OS? by gnud · · Score: 2, Insightful

      Because your paging algorithm will be much less tested, used and bugfixed than any OS paging algorithm. And the memory you allocated might be swapped out by the OS anyway.

    12. Re:Why trust the OS? by Cassini2 · · Score: 1

      This was done back in the Windows 2.0 days with segmented memory. It was a disaster. Every pointer/array access requires incurs significant overheads. VM (Virtual Memory) is the preferred approach because for most applications it results in significant performance improvements.

      Three different memory access scenarios need to be considered:
      1. Memory block is already in memory, and in the current page/segment. If memory is presented as an array of linear blocks, then the processor can simply access the relevant segment. If the memory paging is done manually with software, then software must check if it can simply access the block. The software VM solution is slower in this case.
      2. Memory block is in memory, and in a different page/segment. The VM hardware on an x86 processor can deal with this optimally. If paging is done in manually with software, then the software needs to do it's routine, and then the VM will do it's routine too. Thus, the VM operation is done twice by a software approach. The software VM solution is slower in this case too.
      3. Memory block is not in memory. Either way, you are paging to disk. The only performance gain is if your software solution is much better at reducing pages to disk than the operating system's solution. In practice, it is hard to beat the operating system.

      The fundamental problem is that the gains by managing your own virtual memory in #3 must be significant enough to justify the software overhead in #1 and #2. The software overhead in #1 and #2 is huge, because it is on every memory access. Also, memory prices are constantly falling. The software vendor runs the risk that a customer that really needs more memory to reduce paging activity, may simply purchase more RAM. With the hardware VM approach, the speed gains are immediate. With a software approach, adding more RAM has less benefit, because the speed loss in #1 and #2 is still on every memory access, even if software VM is not needed.

      If VM is causing a serious performance problem for a given application, then likely you need one of these three solutions:
      1. Switch off VM, and don't use a backing store.
      2. Write your own VM allocation routines. This is doable under Linux.
      3. Enable Intel's "Big Pages" option. This increases the page size to 4 MB. It is intended for embedded applications, that do not want their pages swapped to disk. The "Big Pages" option significantly reduces page change overhead inside the operating system, and works well for applications that do not need and/or do not use disk as a backing store.

      Finally, remember that "RAM" memory is itself an abstraction when running in user-mode under most operating systems. Specifically, even if the destination address is in hardware RAM, the page lookup table introduces a delay when switching pages. For most operating systems, pages are 4KB bytes long. This gives 4KB bytes times 1024 TLB pages as the maximum "quickly" available memory. As such, a program can only quickly access 4 MB of RAM. With Big Pages, 4 KB becomes 4 MB, and the program can quickly access 4 GB of RAM.

    13. Re:Why trust the OS? by Hurricane78 · · Score: 1

      You’re a C programmer, right? ;)

      Protip: It is extremely likely someone already invented a better wheel (library/API/OS part) than you. Use it.

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    14. Re:Why trust the OS? by azmodean+1 · · Score: 1

      I see, and that helps the other apps on the box how?

      I can understand where you're coming from, but you're thinking like a sysadmin, not a programmer. For general-purpose software we can't afford to take shortcuts like that, our software needs to be well-behaved or else someone else's well-behaved software gets used because it integrates better.

      The example from the article describes a setup where the application is installed on three dedicated boxen, but how about MY use-case where I want some lightweight proxying in addition to the same box providing firewalling, DNS lookup, NTP server, NFS access, distcc, and a DLNA server? If I install YOUR proxy, I'll immediately uninstall it because it pins 80% of my RAM, or more likely I'd just never find out about it because that's just not something that's necessary for the application.

    15. Re:Why trust the OS? by foksoft · · Score: 1

      So why e.g. MS SQL Server does it exactly as GP wrote?
      Also you can use much better algorithm for data aging than OS. You know your data and you know what is better to keep and what to let go to secondary storage.
      But yes for applications where massive swapping is expected the strategy described might be useful.
      I was always wondering if there couldn't be something similar done for code by compilers. So if you have application, that is swapped out and looping in wait loop, then this loop will ideally fit into very small memory footprint and leave RAM for better use of active processes.

  20. well by larry+bagina · · Score: 2, Informative

    I don't have time to read through the article and verify the numbers (at least right now) but anyone who's even paged through TAOCP knows it was written for computers where "swap" was what the operator did when the tape was full. (Ok, they also had drum memory).

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

  21. This deserves a beer. by turing_m · · Score: 3, Funny

    If you meet him some day, and you think this stuff is worth it, buy him a beer.

    --
    If I have seen further it is by stealing the Intellectual Property of giants.
  22. Stupid headline by Sloppy · · Score: 3, Insightful

    Good article (increase your locality to get fewer page faults). Stupidly wrong Slashdot headline and summary. "Off by ten error?" Please!

    kdawson, next time, RTFA before you post someone's lame summary.

    --
    As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
    1. Re:Stupid headline by fishexe · · Score: 1

      kdawson, next time, RTFA before you post someone's lame summary.

      Yeah, it's a sad day on /. when TFS doesn't even RTFA.

      --
      "I don't care about the Constitution!" --Bill O'Reilly, November 17, 2009
  23. Summary is wrong - btrees != binary trees by SashaMan · · Score: 3, Informative

    The summary is wrong when it talks about "an off by ten error in btrees". In fact, the article talks about how normal binary heap implementations are slow when virtual memory is taken into account.

    In fact, b-trees ARE cache aware and ARE optimized to limit paging on disk. PHK's algorithm is essentially a cache-aware version of a binary heap.

    That is, binary tree is to b-tree as binary heap is to PHK's b-heap.

    1. Re:Summary is wrong - btrees != binary trees by Anonymous Coward · · Score: 0

      binary tree is to b-tree as binary heap is to PHK's b-heap.

      And thus the name, "B-heap". As was stated specifically in the article, his colleague Colin Percival noted the similarity you mention above, and suggested the name "B-heap" by analogy with the name "B-tree".

    2. Re:Summary is wrong - btrees != binary trees by Anonymous Coward · · Score: 0

      At work, don't have plrogramming pearls to hand but bentley in it pointed out that binary heaps can be widened. This would have an obvious effect on cache. Naff article.

  24. This headline is silly by MadAndy · · Score: 4, Informative
    Knuth's stuff assumes everything is RAM-resident - as long as you don't violate that what he wrote is as valid as ever. I'm quite certain that he'll have different suggestions for tasks involving storing data on disk. Even though the disk writes are implicit because the OS is doing them, they're still there, just as they would be had he coded them explicitly. So of course you're going to get poor performance using a RAM-resident algorithm for a disk-resident application.

    The RAM resident stuff is still useful, both at a lower level, but also for those of us creating applications that can live entirely in memory. A web site I did recently is careful to ensure that the entire primary data set can fit in memory, and for that site everything he wrote is still perfectly valid.

    In fact, for very high performing websites you try to ensure that at least most of your requests come from memory rather than disk, which makes Knuth's stuff more important than ever. If you can't do it in RAM then you'd better have a lot of spindles!

    1. Re:This headline is silly by RzUpAnmsCwrds · · Score: 1

      Knuth's stuff assumes everything is RAM-resident - as long as you don't violate that what he wrote is as valid as ever.

      CPU cache.

    2. Re:This headline is silly by Anonymous Coward · · Score: 0

      My understanding is that Google's search index database lives entirely in RAM, simply for the speed.

    3. Re:This headline is silly by Anonymous Coward · · Score: 0

      Knuth's stuff assumes everything is RAM-resident - as long as you don't violate that what he wrote is as valid as ever.

      Don't forget Knuth's section on tape drive algorithms. While a tape drive isn't the same thing as cache (sequential vs paged random access), a lot of the concepts carry over without too much adaptation.

    4. Re:This headline is silly by Anonymous Coward · · Score: 0

      Knuth's stuff assumes everything is RAM-resident - as long as you don't violate that what he wrote is as valid as ever.

      CPU cache.

      Knuth's stuff assumes nothing about hardware. It only calculates how many cycles and operations something takes.

  25. Timer wheels by 0xABADC0DA · · Score: 1

    Continuing a discussion...

    Seems to be that this bheap just reduces the number of pages probably needed from log(n) to log(n)/C where C is the number of levels that are stored in the same page. And for removing a node it may need to access log(n)/C random pages. So this is just a constant factor improvement... it's just that the constant is number of pages so has a large real world cost.

    I'd like to get people's thoughts on using timer wheels instead, like the linux kernel uses for timers. Say you take say 8 wheels of increasing spans of time where each wheel is just an unordered list:

    insert: one of the 8 wheel list-ending pages must be resident (certainly will be)
    delete: just zero out the list entry (probably 1 page-in).
    remove min: 1 page to pop the list head at wheel 0, or a bunch of sequential accesses to cascade the expire timers down.

    Could some data structure expert please comment on the relative merits of bheap vs timer wheels? Seems to me that a small fixed set of pages and sequential access should be far better in terms of swapping. The OS should be designed to recognize in-order access, especially if each list is a mmap'd file, and the thread blocked does not need to have any locks (you can replace the list with a new one while it is being processed).

    1. Re:Timer wheels by chhamilton · · Score: 2, Informative

      The main reason they are using the buckets is to delay sorting costs as far as possible into the future so that there is less cost for most timers (as most timers are apparently deleted far before expiring). I'd suggest that the major performance gain is due to this lazy sorting, and not because their data structure avoids page faults. (Well, it does avoid page faults that the old linked list algorithm would have caused, but these page faults are due to the sorting going on in the original code which is avoided in the second. If timers did not expire, the two approaches would be quite similar, both generating page faults when sorting the linked lists, which likely have bad locality, and neither being as good as an IO-efficient algorithm.)

      Using timer wheels as a heap structure wouldn't be appropriate unless many of the objects placed in the heap are removed prior to making it to the top of the heap. If this is not the case the sorting of the items from one bucket to the next bucket (sorting a linked list) would cause many page faults if the list didn't fit in internal memory. Timer wheels do nothing to address data locality which is the main problem faced by extremely large heaps. Your mention of in-order access is only true if the lists at each bucket as indeed stored sequentially in memory. This is hard to guarantee unless that space is reserved ahead of time or some dynamic reallocation scheme is used. I read the linked article as implying that simple linked lists were used, which generally have very bad data locality. Even if if a linear list was guaranteed, however, the sorting step when pushing things from one bucket down to the next bucket would incur page faults (assuming the list was too big to fit in memory) unless an I/O-efficient or cache-oblivious sort were used. (Which could easily be done, making an IO-efficient timer wheel structure.)

      The algorithm discussed in the article is for a general purpose heap. In most heaps the main cost is in removing elements from the root of the heap as they bubble up through it, rather than deleting them prematurely (as is the case with timers). Different approaches for fundamentally different problems.

    2. Re:Timer wheels by Anonymous Coward · · Score: 0

      In the kernel timers wheels work by lazy sorting... avoiding sorting when it's not needed. There is no paging since linux kernel memory is not paged.

      In a caching http proxy, the cost is from paging, not from sorting. Timer wheels would work then by lazy paging... putting off paging until it can be done in-order.

      What is the cost of paging anyway? It's the randomness of the accesses. For a hard drive, it's the seek time. For an SSD it's the cost to set up and perform an IO operation for just one small page. So by using timer wheels, where all paging could be sequential, the system can avoid seeking and set up a few large reads of many pages at once.

      And finally, no bucket ever needs to be sorted; if the smallest bucket is "expires in the next 5 minutes" one can simple wait 5 minutes then expire all of those pages in whatever order they happen to be in. There's no requirement to expire pages in any particular absolute order.

      Can anyone refute these points?

  26. Don Knuth pays people who find errors by peter303 · · Score: 2, Interesting

    I forget the exact amount, but it was like PI or E dollars for every typo. I am not sure what the payment is for an algorithmic error.

    1. Re:Don Knuth pays people who find errors by Anonymous Coward · · Score: 0

      it's 2.56, a hexadecimal dollar

    2. Re:Don Knuth pays people who find errors by kybred · · Score: 2, Funny

      I forget the exact amount, but it was like PI or E dollars for every typo. I am not sure what the payment is for an algorithmic error.

      I think it's e ^i(pi/2)

  27. Seymour Cray on virtual memory by shoppa · · Score: 3, Insightful

    "Virtual memory leads to virtual performance."

    Just what I always wanted, a B-tree implementation that is guaranteed to swap.

    1. Re:Seymour Cray on virtual memory by prockcore · · Score: 1

      Just what I always wanted, a B-tree implementation that is guaranteed to swap.

      Isn't that pretty much every SQL database ever made?

  28. Virtual Address vs Paging to Disk by frist · · Score: 1

    The author of the article doesn't seem to understand the difference.

    1. Re:Virtual Address vs Paging to Disk by evanh · · Score: 1

      Spot on.

  29. Don't Trust the OS! by amcdiarmid · · Score: 1

    In a virtual world it lies: I suspect that most Operating Systems lie about what physical hardware:

    VMware allows for over-commitment of most hardware. (CPU, Memory, and Hard Disk). Windows allows for over-commitment of Memory

    Since this is making assumptions about memory management: (Flash: Various algorithms may be tuned for optimized use in your specific use-case).

    In your case of grabbing 80% of memory: This works if you really need the memory - in which case you have to have it: If this forces Windows (linux, whatever) to swap some "system" memory it make slow down system processes (disk write, responding to network requests, running tomcat...) and cause your system to slow down. Perhaps it works for you.

    If your "system" resides in VMware, your memory may be a swap file depending on over-commitment. Say some Joe-Rent-a-Network has connected you a server in a "secure" location. In a Co-Lo. On VMware. Now if each system has an application (or two) that grabs 80% of available memory...

    Lets say Your 80% memory grab meets the swap file, across a network link to the cheapo SAN...

    If I'm Joe Rent-a-Network and you make me have to go figure out why performance sucks for everyone I'm gonna kick your ass.
    Now get off my lawn

    1. Re:Don't Trust the OS! by michaelmalak · · Score: 1

      In Windows, the API to allocate physical memory is VirtualAlloc.

      Good point about VMWare. I hadn't thought about that.

      I just used 80% as an example. Obviously one would provide command-line switches or config options for either X% of memory or Y MB of memory.

    2. Re:Don't Trust the OS! by w_dragon · · Score: 1

      This is a stupid idea to begin with. Unless you're running on a system where you have in depth knowledge of how the memory is arranged and managed, like on an embedded system, the OS knows how to handle memory better than you do.

    3. Re:Don't Trust the OS! by snemarch · · Score: 1

      Ignoring AWE, VirtualAlloc doesn't give any guarantees about physical memory - it, at most, gives you a contiguous range of address space. Yes, you can specify MEM_COMMIT, but this doesn't guarantee that memory won't eventually be paged out.

      There's VirtualLock, but "Each version of Windows has a limit on the maximum number of pages a process can lock. This limit is intentionally small to avoid severe performance degradation."

      --
      Coffee-driven development.
  30. "Knuth got it wrong" by $RANDOMLUSER · · Score: 1

    Parser error.

    --
    No folly is more costly than the folly of intolerant idealism. - Winston Churchill
  31. Re:Theoretical performance vs real-world performan by Darinbob · · Score: 3, Insightful

    But everyone already knows that (or should). Knuth knows that as well, caches and paging systems are not unknown things to him. He was writing a text book for students, and simplified a complicated problem to the point where it can be studied and analyzed more easily. Similar to teaching students Newtonian physics. It is sensationalist and naive to call Knuth wrong here.

  32. Next news headline by Darinbob · · Score: 1

    Extra, Extra!
    GOTO Successfully Used Without Harm!

  33. kdawsonfud, kdawsonsucks by Nimey · · Score: 0, Troll

    Funny how often I wind up using those tags.

    --
    Hail Eris, full of mischief...

    E pluribus sanguinem
  34. Careful there... by Estanislao+Mart�nez · · Score: 3, Informative

    This means that algorithms in the real world can scale worse than their theoretical "worst-case", if that theoretical worst-case scaling is based on the assumption of constant memory access cost, since that assumption does not hold in the real world.

    I agree with all of your post except this part. Algorithmic complexity theory is about orders of magnitude, not about precise numbers. That's why we have O(n) as a complexity class but not O(2n), O(3n) as separate classes; saying that an algorithm has O(n) worst-case time performance is saying that the time it takes to run it is approximated by some linear function of the problem size. We don't particularly care which linear function it is, because that depends too closely on your assumptions about the computational model and/or hardware. What we really care about when we call it O(n) is that that's better than something like O(n^2) (a.k.a. polynomial time or just "P") or O(log n), no matter what computational model you assume.

    As long as the slow memory accesses in the physical hardware still respect some bound, you can treat that upper bound as the constant worst-case memory access cost, and use the algorithmic complexity analysis to calculate an upper bound on the algorithmic complexity. If we turn your argument on its head, we'd say instead that the actual physical cost of running algorithms is often faster than the complexity class indicates because many memory accesses are much faster than the constant upper bound, but that doesn't make the linear upper bound invalid. The best you might be able to do is to assume a finer-grained computational model with variable cost memory access, and prove that you can get a lower upper bound there, but the original higher upper bound is still an upper bound for the computational model chosen, and can still be useful when reasoning about a system.

    1. Re:Careful there... by Bigjeff5 · · Score: 0

      I agree with all of your post except this part. Algorithmic complexity theory is about orders of magnitude, not about precise numbers. That's why we have O(n) as a complexity class but not O(2n), O(3n) as separate classes; saying that an algorithm has O(n) worst-case time performance is saying that the time it takes to run it is approximated by some linear function of the problem size.

      You're missing the point. With regards to memory, the reality is that disk cache is not just a single order of magnitude slower than RAM (which would allow what you describe to be true), it's several orders of magnitude slower than RAM. Assuming all cache is equal you may show a worst case scenario of O(n), however if the reality is that half of your cache runs at 1/100th the speed of the other half, the actual real worst case scenario is easily more like O(n^2) or higher.

      It means the algorithm is an order of magnitude or more less efficient than its worst case scenario would suggest because of a misleading assumption.

      --
      Security is mostly a superstition... Avoiding danger is no safer in the long run than outright exposure. - Helen Keller
    2. Re:Careful there... by Rakishi · · Score: 4, Informative

      No, you're missing the point. And wrong. And also missing a lot knowledge about what O() means.

      It doesn't matter how many orders of magnitude slower an operation is. O() is about SCALING for input size n. That's all. Constant factors do not matter. The GP already said this, please pay bloody attention next time. The running time of each operation is just a constant and has no impact on the O() performance. An order of magnitude or fifty is all the same. You talk about 1/100 speed and compare n to n^2. Hahahaha. Take n = 1000000. You know what the difference between n and n^2 is then? 1000000. Your puny factor of 100 is irrelevant against six orders of magnitude performance difference.

      The worst case performance does not change. It's still O(n) or O (n^2). In fact it's quite possible for an O(n^2) algorithm to be faster than an O(log(n)) algorithm for small n under certain conditions. O is all about n being so bloody large that constant factors don't matter anymore.

      This is all basic introductory algorithms stuff, please read up on it before trying to chime in on any arguments related it it in the future, okay?

    3. Re:Careful there... by Rakishi · · Score: 2, Informative

      Sigh. No, the GP doesn't know what he's talking about. And apparently neither do you. If he did he would not mention something as idiotic as cache making the algorithm go from O(n) to O(n^2). It makes it go from O(x*n) to O(100*x*n), both of which are O(n). But if n is 50, O(x*n^2) would come out faster.

      You're both confusing the very real issue of the constant running time of operations and O algorithm scaling. The algorithm is still O(n) however for the data sets in question it's slower than an O(n^2) algorithm. The worst case O performance is identical, that is simply a question of scaling to data sizes. However the practical constant factors are now much larger than one would normally expect and they vary based on other factors.

      It's a simple distinction, really, which is why I'm confused at people's inability to grasp it.

      I said nothing about the article in question or anything related to it on purpose. That is because none of the stuff you mentioned had really anything to do with that. Not specifically and the article makes no claims that agree with you. This is simply an argument about what worst case and O notation refers to.

      The article essentially is about finding a way to reduce the constant factor in an algorithm. The O notation makes no sense in this case. It's still O(n) or whatnot. Except it's now 10 times faster.

      Honestly, slashdot keeps letting me down these days. Sigh.

    4. Re:Careful there... by Eskarel · · Score: 1

      It's a bit more complicated than that.

      It's been a while since I did an algorithm class, but my recollection is that O() notation is indeed about the scaling of operations with regards to the input size(n), and generally speaking constants are indeed usually ignored.

      The issue however is that all operations are not equal. A moderate speed modern desktop CPU can perform something on the order of 6 and a half billion internal operations in a second, whereas even under the assumptions of the article using a 1 ms access time for hard disk, you can only get 1000 disk operations in a second, a difference of six orders of magnitude.

      Knuth's algorithms presume a data access cost of O(1), whereas even on a desktop you're really looking at O(1000000) for some operations and O(1) for others. You still want to minimize operations of course, but if you're accessing disk most of the time, you'd have to have an input size of a million just to break even between the O(n) and O(n^2) algorithms even on a basic desktop.

      I'm aware that this is an over simplification since cache and RAM are nowhere near as slow as disk, but the point is that if you're accessing disk a lot then you need a very large n to see a substantial speed increase.

    5. Re:Careful there... by Nitage · · Score: 2, Insightful

      He does know what he's talking about.

      Where, n is the number of items stored, the lookup time is given by log(n)*COMPARRISON_COST + log(n)*MEMORY_ACCESS_COST.
      That gives O(logn) only if COMPARRISON_COST and MEMORY_ACCESS_COST are *constant* - the entire point of the article is that MEMORY_ACCESS_COST is not constant, but increases as n increases.

    6. Re:Careful there... by Nitage · · Score: 2, Informative

      O(1) *is* O(100000). The point of the article is that memory access is not O(1) - it's O(n) or worse.

    7. Re:Careful there... by Anonymous Coward · · Score: 0

      Sorry, but the GP is right. He skimps on the math, but the result is right. Let me show you.

      Assume a cache hierarchy where every level is twice as big as the previous, but also twice as slow. Now take an algorithm and an input such that caches up to level L are needed. Assume that when we double the input size, the memory used in calculations also doubles. In this case, we need caches up to level L+1. The speed of the average memory access is now halved. If the algorithm takes c*N memory accesses, the bigger input will require c*2N memory accesses. The time that takes will have increased from c*N*t(L) to c*2N*t(L+1) = c*2N*2*t(L). Hence, we see for this reasonable case that the memory access time increases by a factor of 4 when the input doubles. Hence, barring other bottlenecks, this algorithm is O(N*N).

      With the same memory hierarchy, the runtime can be worse than O(N*N) when the memory use is worse than O(N). Doubling the input size would then need more then one extra level of cache, and thus increase the runtime by more than a factor of 4.

    8. Re:Careful there... by Rakishi · · Score: 2, Insightful

      Except it's a bounded increase. That's my whole point. There is nothing slower than the hard drive to cache from. You can assume every operation has the worst possible access time and you'd still end up with the same O() running time.

      log(n)*COMPARRISON_COST + log(n)*MEMORY_ACCESS_COST log(n)*COMPARRISON_COST + log(n)*MEMORY_ACCESS_COST_MAX CONSTANT*log(n)

    9. Re:Careful there... by Rakishi · · Score: 1

      Now you're creating assumptions and a new problem definition after the fact. Sorry, it doesn't work that way. The GP explicitly failed to define such a hierarchy and explicitly talked of only two levels of cache. Two levels with a single constant access time difference between them. Within that framework he made an absurd statement about what running time is and how it deals with constants.

      That is the context in which I posted my reply. Of course it's wrong if you change the problem we're dealing with but that's irrelevant. A hierarchy will cause the effect you want and probably is a saner way to think about this mathematically. It's nonetheless not what was being discussed as far as I could tell.

      After all, the article concerns a modern computer which has a very limited hierarchy of caches. In other words the worst cache access time is known and is a constant independent of n.

    10. Re:Careful there... by Anonymous Coward · · Score: 0

      What we really care about when we call it O(n) is that that's better than something like O(n^2) (a.k.a. polynomial time or just "P") or O(log n), no matter what computational model you assume.

      O(n) is also polynomial complexity.

    11. Re:Careful there... by DragonWriter · · Score: 1

      I agree with all of your post except this part. Algorithmic complexity theory is about orders of magnitude, not about precise numbers. That's why we have O(n) as a complexity class but not O(2n), O(3n) as separate classes; saying that an algorithm has O(n) worst-case time performance is saying that the time it takes to run it is approximated by some linear function of the problem size.

      Right. And if that is true based on the assumption that all memory accessed by the system has an equal and constant access costs, but in the real world (because of cache) memory does not have equal and constant access cost, an algorithm which has O(n) theoretical performance under the assumption of equal and constant memory access cost may not scale even approximately linearly on a real world system -- it may scale quadratically or even worse, depending on it smemory access pattern and the structure of the underlying cache layers.

      (Assuming that consistent cache misses result in constant time [albeit slow] access, the big-O of the algorithm would still be a valid asymptotic limit, though misleading in terms of real-world performance, but I'm not sure that assumption is valid of real world caches. The big point is that any a priori performance analysis rests on some set of assumptions about the characteristics of a system, and says nothing about the performance of a system that does not share those characteristics.)

      What we really care about when we call it O(n) is that that's better than something like O(n^2) (a.k.a. polynomial time [wikipedia.org] or just "P") or O(log n), no matter what computational model you assume.

      That's nonsense unless you mean "computational model" in a sense that is irrelevant to the immediate issue. If all you know is that an algorithm that has an asymptotic running time that is O(n) under the assumption of constant-cost memory access, you don't know the order of the asymptotic limit of its running time on a system that doesn't have constant-cost memory access. Under a particular scheme of non-constant-cost memory access, it might be O(n), it might be O(n log n), it might be O(n^n), it might be something else.

      If the assumptions under which the performance scaling were calculated don't apply to your situation, neither does the calculation.

    12. Re:Careful there... by DragonWriter · · Score: 1

      Except it's a bounded increase. That's my whole point. There is nothing slower than the hard drive to cache from.

      That still doesn't make the assumption of constant memory cost valid, even in the asymptotic case, unless all cache misses are created equal such that cache misses act like direct random access, and the algorithm asymptotically approaches a fixed cache miss rate.

      Since hard drives aren't random access devices, anyway, even ignoring cacheing, this is unlikely.

    13. Re:Careful there... by Crackez · · Score: 1

      If you are going to rip people apart, you have at least two syntax errors:

      log(n)*COMPARRISON_COST + log(n)*MEMORY_ACCESS_COST ^^here^^ log(n)*COMPARRISON_COST + log(n)*MEMORY_ACCESS_COST_MAX ^^and_here^^ CONSTANT*log(n)

      What operation should replace ^^here^^ and ^^and_here^^ ?

      Also, you don't know how to spell COMPARISON.

      Remember, you seem to think everyone else is an idiot, so you must be both precise and accurate lest you will be misunderstood.

      Not that I would be picking sides here, but at least Estanislao Martínez appeared to be trying to have an scholarly discussion. Politeness goes along way. Not everyone is as smart as the next guy, but if they are trying then they at least deserve some decency.

    14. Re:Careful there... by Anonymous Coward · · Score: 0

      In fact it's quite possible for an O(n^2) algorithm to be faster than an O(log(n)) algorithm for small n under certain conditions.

      Isn't that what the article is saying? Am I being made a fool of?!

    15. Re:Careful there... by Anonymous Coward · · Score: 0

      It's not just that n gets so large that the constant factors don't matter.

      The real issue is that the ONLY time you should care even a little bit about the big-O relative performance of your algorithms tends to be precisely those times when n is large enough to make the performance impact of the memory hierarchy relevant.

      This is like teaching people to make their climbing harness out of piano-wire. When you aren't falling, it doesn't matter whether you used nylon webbing or piano wire, but when you actually NEED the harness the piano wire one cuts your legs off.

    16. Re:Careful there... by Anonymous Coward · · Score: 0

      Sorry, you forgot pre-emption, cache-misses, page misses... and so on and so on.

      Knuth's calculations like log(n) is only theoretical performance for algorithm and is only absolute general measurement for some algorithm. Real world performance will be different and is too difficult to calculate for any sane comparisons. Say your OS might swap or might not swap, because of all those adult materials you we're loading while time testing your algorithm...

      Please, go to school and take your CS courses!

    17. Re:Careful there... by synth7 · · Score: 1

      If you're going to chime in, please be sure to read the whole tree of the comment thread above the post you wish to dissect. The spelling and syntax issues are directly quoted from the silly punt that Rakishi is trying to correct, so those errors are attributable to Nitage, not Rakishi. My assertion here is: If you're going to snipe, make sure you have the right target.

    18. Re:Careful there... by Eskarel · · Score: 1

      I know that from a purely technical point of view O(c) is O(1), but when c is 1000,000 times slower than O(1) then you're making an ass of yourself for anything other than a really gigantic data set.

      That's really the big problem with using O() notation in the first place. Because it's entirely concerned with scaling, all constants get filtered out on the presumption that for a sufficiently large data set the constants don't matter. The problem is that when you constants get particularly large, you need a fairly large data set before that's actually true.

    19. Re:Careful there... by Nitage · · Score: 1

      If the raw physical limits of machines are taken into account, every algorithm becomes O(1).

      Your logic is an exact analogy to "Bubblesort is O(1) - a naive analysis says O(n^2), but because n is bounded to 2^64 on 64 bit machines, it's actually O(2^128) which is actually O(1)".

    20. Re:Careful there... by Nitage · · Score: 1

      Spelling errors yes, syntax errors no. So do please read the whole tree of the comment thread above the post you wish to dissect.

  35. Does he get a check? by sukotto · · Score: 1

    I'm interested to see if this counts as a true error and thus deserving a check.

    --
    Come play free flash games on Kongregate!
    1. Re:Does he get a check? by Nebulo · · Score: 1

      I believe Knuth pays for bugs in code, not misconceptions or obsolescence.

      Nebulo

    2. Re:Does he get a check? by butlerm · · Score: 1

      Not even close. He didn't discover any kind of error at all, just trumpeting a fact that has been well known to database designers for about four decades now.

  36. Discrete Math &/or DataStructures material by Anonymous Coward · · Score: 0

    "Knuth's analysis is valid in the framework of his assumptions, and what is described in the linked article has been known as "cache oblivious b-tree" for not so short time." - by siddesu (698447) on Monday June 14, @07:29PM (#32572714)

    The entire discussion in the article really reminded me of 2 classes from academia: Discrete Math (where you see the Set Theory, Probability Theory, Logic, & the P-NP type material discussed in this article), & DataStructures (where you learn about Binary Trees and implementations via computer algorithms of them (which leads into things like Tri-E etc.)).

    I'd absolutely HIGHLY recommend both courses to any CSC student in fact (they BOTH make you *THINK*, & much more than other classes I felt @ least, did...).

    Why?

    Heh - it was the ONLY things that allowed me to "keep up" with some of the article's material is why... lol! Being "familiar beforehand" tends to help that way, you know?

    APK

    P.S.=> The MORE DIFFICULT of the two subject though, imo @ least? Discrete Math (for me @ least) - As I felt that you don't just "learn it by rote only" & just "doing your homework" only either, as many other maths are like... this one?? You have to have your "thinking cap on", 24x7 in it... still, it's GOOD stuff! apk

    1. Re:Discrete Math &/or DataStructures material by Anonymous Coward · · Score: 0

      Ok Kids, come a bit closer!
      Here you can see the effects of long-term Perl misuse. Horrible, isn't it?
      No need to be afraid, it's strong glass he's behind.

    2. Re:Discrete Math &/or DataStructures material by azmodean+1 · · Score: 1

      I had the same experience with Discrete Math and "Implementation and Optimization of Algorithms", which were actually synchronized such that you would be covering theory in Discrete Math that had application in "IOA". My favorite pair of classes in my major. Haven't had that much of a chance to use them in my career though *sigh*.

    3. Re:Discrete Math &/or DataStructures material by Anonymous Coward · · Score: 0

      You are just another troll and the kind of online weasel everyone can't stand. I think you're nothing but some online punk the poster you are trolling has gotten the best of at some point and you are only sore about it and trying to get your revenge and failing because youre just too stupid in computers to be on topic here on this computer science based topic. Go away troll.

  37. Many servers by tepples · · Score: 4, Informative

    Unless you have many servers

    The article does in fact mention many servers, specifically replacing twelve Squid servers with three Varnish servers.

    it is cheaper to throw money at the problem in the form of physical RAM before you start thinking about problems like this.

    No matter how much physical RAM you have, you're still limited by the speed of the interface between RAM and the CPU. If a set of closely related nodes can fit in a cache line, this improves locality so that the CPU can do more work instead of twiddling its thumbs.

    1. Re:Many servers by ThePhilips · · Score: 0, Troll

      If a set of closely related nodes can fit in a cache line, this improves locality so that the CPU can do more work instead of twiddling its thumbs.

      That's sort of ... obvious? But off-topic.

      RTFA: it revolves around I/O optimization. It was tested on system with 16GB RAM and 300GB mmaped storage. LOL. Essentially author claims that if you use binary tree for on-disk data look-ups it would be *surprise* very slow. Then he goes on to reinvent some b-trees, tuned for the task at hand, and shows how they are 10 times faster.

      --
      All hope abandon ye who enter here.
  38. Re:Theoretical performance vs real-world performan by Palinchron · · Score: 1

    For instance, Knuth's analysis that the author of the article here holds to be misleading (not, as the Slashdot title suggests, "wrong") calculates the complexity based on the assumption of ideal random access memory, that is, memory for which all accesses are equal cost.

    No, it assumes memory for which all access are *at worst* a certain equal cost - in other words, memory for which accesses have an upper bound. Knuth's analysis still holds if certain pieces of memory are FASTER than the norm. If we take memory access going through swap as the normal, worst case, upper-bound cost of memory access, and RAM and cache hits as special better cases, the analysis still applies to the real world.

    This means that algorithms in the real world can scale worse than their theoretical "worst-case", if that theoretical worst-case scaling is based on the assumption of constant memory access cost, since that assumption does not hold in the real world.

    Doesn't it? The theoretical worst case corresponds nicely to the real-world worst case of all memory coming from swap. The (typical) case in which there is also a bunch of fast RAM and even faster CPU caches is just not the worst case.

    --
    The lesson here is that a sufficiently large corporation is indistinguishable from government. --ultranova
  39. You can quote xkcd... by Culture20 · · Score: 1

    Just don't quote Monty Python or Munroe will mock you. http://xkcd.com/16/

  40. Alas, no more by l00sr · · Score: 4, Interesting

    Unfortunately, he no longer gives out reward checks for finding bugs in his texts. This seems to be mostly because proud bug-finders inevitably post images of the checks online, which of course, contain Knuth's bank account numbers. More discussion here.

  41. He is old, but... by l00sr · · Score: 1

    ...not dead yet, to quote Monty Python.

  42. Yes, but... by l00sr · · Score: 2, Funny

    He's one of the top three UNIX gurus in the entire world. In fact, the Internet today is what it is thanks to his hard work and dedication.

    Still, I'd trust Don Knuth over Poul-Henning any day--at least Knuth can spell his own first name correctly.

  43. What Is This Knuth? by Anonymous Coward · · Score: 0

    One assumes Knuth the KDE clone of Gnuth.

    1. Re:What Is This Knuth? by $RANDOMLUSER · · Score: 1

      For those of you keeping track, that's pretty goddam funny.

      --
      No folly is more costly than the folly of intolerant idealism. - Winston Churchill
  44. Read of database research.. by Anonymous Coward · · Score: 0

    Come on!! Anyone who has read last 30 years of database research knows data structures which take into account locality of reference perform better. Any commercial database has lots of similar tricks to provide better performance than home-grown datastructures. The article is technically correct, just not something that is new. Anyone implementing large database systems knows this. Most of this work is done within commercial systems so open sources programming wake up one day and think they discovered something know. Go and read ant SIGMOD or VLDB paper and you will find similar claims.

  45. Figure #5's a BINARY TREE though... apk by Anonymous Coward · · Score: 0

    "No, and no. The data structure described by Henning-Kamp is not a B-tree, but a heap" - by jemfinch (94833) on Monday June 14, @09:13PM (#32573608) Homepage

    It does appear from "Figure 5" though that it's a typical "Binary-Tree" construct though... I mean, look at HOW it's structured in its node elements!

    I.E.->

    ---

    1.) Start with midpoint of dataset as top most parent node since its a BINARY SEARCH involved (easy enough to determine using two pointers (or array indices really even) & doubling the 2nd pointer/array index as to it's size/position for the 2nd one, & keep on doing it, until it "errs-out"/abends trying to double said 2nd pointer/array index location (vs. the first one), which then you can use a Try-Catch type err handler to yield you the midpoint of said dataset which the first "1/2 sized pointer/array index" will then have the value of (you can do this w/out array bound checking on this way even & NOT "Crash", or with it on (overriding std. structured err-handler of array index out of bounds errs too)))...

    You can do this "puny trick" above, in order to find said "midpoints" of datasets, even w/out its TOTAL items count being known beforehand.

    2.) Then, send each potential child node off to where they belong comparing to nodes as you go, & placing "smaller-than-compared-to-potential parent" child node candidate item to left of said "potential parent/compared-to" node, & larger child node candidate off to right of said "compared-to potential parent" node possible, in order to place child nodes off parents, etc./et al though.

    3.) AND, "off you go", to "the land F A S T binary seeks" of items!

    ---

    (Yes - Oversimplified maybe, but that's as best as I know how to "put it on paper" fast/offhand @ least)

    Tell me if I am "off" here, as it's been awhile since I visited this type of material... it seriously re-reminds me of DataStructures class in combination with Discrete Math class materials, which is why I posted this here, originally -> http://developers.slashdot.org/comments.pl?sid=1686094&cid=32573724 !

    This type of article?? It's the "WHY" of why I frequent this website's pages...

    (As every once in a while, there is a "WILD" article about CSC "breakthroughs & ideas", & what-not, that I like reading! This WAS "one of those times"... good stuff!)

    APK

    P.S.=> Anyhow/anyways: It was good to see they are into using "SSD's" too, to lessen latencies (been a HUGE fan of those here for decades in software ramdisks, & later with "True SSD's" (that don't use FLASH RAM, which is slower on writes than DDR or PC-1xx RAM is for instance, though caching delay writes can help FLASH one SOME) like the CENATEK RocketDrive &/or the Gigabyte IRAM for example (they're awesome to serve up websites OR DB's for them mind you, in fact, because of such read speeds & LOW latencies + on the type I use (non FLASH RAM based)? F A S T Write too)) & they seem to "lend themselves" to this article's concepts well also (as things like Binary Trees ARE about increasing search speeds too & databases' indexes, iirc, also use them LIKE MAD also and? THEY WORK FOR SPEED!)... apk

  46. KDawson is a(n) [....] by FlyingGuy · · Score: 0, Offtopic

    Pick your deriding descriptive term.

    How in the hell did he ever get promoted or appointed or how ever the hell it is you become one of the anointed few who decide what gets posted on /. and what the headline looks like? I mean really, is he related to someone? Is he the owners kid, nephew, love child?

    --
    Hey KID! Yeah you, get the fuck off my lawn!
    1. Re:KDawson is a(n) [....] by Anonymous Coward · · Score: 0

      Could be worse - Zonk could still be here, too.

  47. Cache oblivious algorithms by Anonymous Coward · · Score: 0

    For a well understood generalization of this "problem" and solutions to it, see http://en.wikipedia.org/wiki/Cache-oblivious_algorithm

    For a simpler model which still captures the behaviour that the author talks about see "the external-memory model"
    It "models a two-level memory system. The first level of memory (the cache) of size M is partitioned into blocks of size B. The second level (main memory or disk ) is limitless but requires us to pay a charge for each access (memory/block transfer). In this model, we measure performance by the number of memory transfers (cache misses)." [ From http://theory.csail.mit.edu/classes/6.897/spring03/scribe_notes/L15/lecture15.pdf ]

    There are well known improvements to data structures in both of these models.

  48. Compare g gravity vs. G gravity by tepples · · Score: 1

    He was writing a text book for students, and simplified a complicated problem to the point where it can be studied and analyzed more easily. Similar to teaching students Newtonian physics.

    I don't find it all that similar. Newtonian mechanics describes behavior of the objects that people see within their daily lives to within measurable noise level. Ideal random-access memory does not. It's as if aerospace engineers were taught the version of gravity with g (Earth sea level acceleration) instead of the version with G*m/(r + h)^2 (acceleration given arbitrary planetary mass, planetary radius, and altitude). g works for land vehicles but not spacecraft, and as a lead-in to discussion of G*m/(r + h)^2, but not as the final word on useful applications of the subject.

    1. Re:Compare g gravity vs. G gravity by rjstanford · · Score: 1

      Of course, when Knuth was writing, there was no disk-backed memory and, IIRC, no processor cache (unless you happen to count leftover register values as cache)... 46 years is a long time in CS. I dare say that if he was writing his seminal works today, he might either expand on the subject or preface it with a series of provisos.

      --
      You're special forces then? That's great! I just love your olympics!
    2. Re:Compare g gravity vs. G gravity by drinkypoo · · Score: 1

      I don't find it all that similar. Newtonian mechanics describes behavior of the objects that people see within their daily lives to within measurable noise level. Ideal random-access memory does not.

      Newtonian physics break down at very high and very low energy levels, and Knuthian sorting works also in the middle ground, on simple RISC processors which are applicable even today. Either way, someone ought to teach you when to use them, and when not to.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
  49. That quote does sound like a doofus by Anonymous Coward · · Score: 1, Insightful

    A 300-GB backing store, memory mapped on a machine with no more than 16 GB of RAM, is quite typical. The user paid for 64 bits of address space, and I am not afraid to use it.

    As an undergraduate in the early 1990s, I am sure I was told about "out of core" algorithms within my first two years in school, including how people were starting to apply these to "out of cache" scenarios. In other words, everyone knows and takes for granted that you do not run a RAM-oriented algorithm such that its working set expands beyond the RAM space that has the access metrics you require. And B-trees/B*-trees are the classic data structure to organize data that is too large for your main working RAM. And the HPC community has been tuning hybrid data structures to live in multi-level RAM hierarchies for a long long time. I don't care how much of a "guru" the author is. If he wants to believe virtual memory is a transparent abstraction (a typical unix acolyte mistake), he is ignoring so much computer science; virtual memory is a slightly more graceful failure handler for temporary resource crises. If your average working set ever meets swapping, you are doing it wrong.

  50. Nothing new.. please move along by cwills · · Score: 3, Informative

    This really isn't anything new. Knuth didn't get it "wrong". He based his analysis of the algorithms assuming a system that had dedicated memory and where each instruction of code ran uninterrupted and in a consistent fashion.

    Certain memory access patterns are "bad" under a system that uses virtual memory, especially when the base system is memory constrained. This has been a well known fact for decades. In fact one of the maybe lost arts of programming was ensuring reference locality, not only of data, but also of code. It was a common practice to ensure that often called subroutines or functions where either located in same page of memory as the calling code, or to group all the often called functions into as few pages of memory as possible.

    Basically, every address space has what is sometimes called a working set, a set of pages that have been recently referenced. There are three things that can happen with a working set. It can remain the same size, it can grow and it can shrink. If it remains the same, there is no additional load to the operating system. If it shrinks, there is no additional load to the operating system, in fact this can help a memory constrained system. A growing working set however an lead to a thrashing system. Some operating systems will monitor working set sizes and can adjust dispatch priorities and execution classes depending on what the recent working set size history is. An application with a growing working set may very will find itself at the end of the queue way behind applications that have a static working set size.

    Take for an example the following very simple program

    static string buffer[256][4096]
    while not infile.eof() do
    infile.readinto(buffer[0],256)
    outfile.writefrom(buffer[0],256)
    end

    Here the working set of this program will be very small. Ignoring the file i/o routines, all the code and data references will be limited to basically a fixed section of memory. From a virtual memory stand point, this is a "well behaved" application.

    Now take the following

    static string buffer[256][4096]
    while not infile.eof() do
    bindex = random(0,4095)
    infile.readinto(buffer[ bindex ], 256)
    outfile.wwritefrom(buffer[ bindex ], 256)
    end

    Functionally the same program, however the data reference pattern here is all over the place. The working set will be large, since many of the buffer pages will be referenced. The program never stays long on the same memory location.

    Finally take the following example

    static string buffer[256][4096]
    infile.readinto(buffer[0], 256* 4096) // fill the entire buffer
    for i = 0 to 4095 do
    numbercrunch( buffer[i] )
    end

    Here there will be an initially huge working set as the data is read in. However, the working set will shrink to a reasonable size once the numbercrunching phase starts since the data references will all be localized to a small block of memory.

    1. Re:Nothing new.. please move along by Anonymous Coward · · Score: 0

      I code in Java, therefore the architecture is irrelevant, you insensitive clod!!!

    2. Re:Nothing new.. please move along by Anonymous Coward · · Score: 0

      This really isn't anything new. Knuth didn't get it "wrong". He based his analysis of the algorithms assuming a system that had dedicated memory and where each instruction of code ran uninterrupted and in a consistent fashion.

      Certain memory access patterns are "bad" under a system that uses virtual memory, especially when the base system is memory constrained. This has been a well known fact for decades. In fact one of the maybe lost arts of programming was ensuring reference locality, not only of data, but also of code. It was a common practice to ensure that often called subroutines or functions where either located in same page of memory as the calling code, or to group all the often called functions into as few pages of memory as possible.

      Basically, every address space has what is sometimes called a working set, a set of pages that have been recently referenced. There are three things that can happen with a working set. It can remain the same size, it can grow and it can shrink. If it remains the same, there is no additional load to the operating system. If it shrinks, there is no additional load to the operating system, in fact this can help a memory constrained system. A growing working set however an lead to a thrashing system. Some operating systems will monitor working set sizes and can adjust dispatch priorities and execution classes depending on what the recent working set size history is. An application with a growing working set may very will find itself at the end of the queue way behind applications that have a static working set size.

      Take for an example the following very simple program

      static string buffer[256][4096]
      while not infile.eof() do
          infile.readinto(buffer[0],256)
          outfile.writefrom(buffer[0],256)
      end

      Here the working set of this program will be very small. Ignoring the file i/o routines, all the code and data references will be limited to basically a fixed section of memory. From a virtual memory stand point, this is a "well behaved" application.

      Now take the following

      static string buffer[256][4096]
      while not infile.eof() do
          bindex = random(0,4095)
          infile.readinto(buffer[ bindex ], 256)
          outfile.wwritefrom(buffer[ bindex ], 256)
      end

      Functionally the same program, however the data reference pattern here is all over the place. The working set will be large, since many of the buffer pages will be referenced. The program never stays long on the same memory location.

      Finally take the following example

      static string buffer[256][4096]
      infile.readinto(buffer[0], 256* 4096) // fill the entire buffer
      for i = 0 to 4095 do
          numbercrunch( buffer[i] )
      end

      Here there will be an initially huge working set as the data is read in. However, the working set will shrink to a reasonable size once the numbercrunching phase starts since the data references will all be localized to a small block of memory.

      swapped to total crap partition.

    3. Re:Nothing new.. please move along by snadrus · · Score: 1

      That's also another plus for the programming style of 1 big function with few GOTOs. Object Oriented's little functions all over the place have a higher penalty.

      --
      Science & open-source build trust from peer review. Learn systems you can trust.
  51. Kdawson got it wrong. by Anonymous Coward · · Score: 1, Funny

    What's with this retarded, inflammatory and incorrect summary? Oh right, it was kdawson.

    Dear slashdot,
    Please fire kdawson and hire someone who's less of a muck-raker to edit your summaries.

    Thanks.

  52. Re:Theoretical performance vs real-world performan by emt377 · · Score: 1

    No, it assumes memory for which all access are *at worst* a certain equal cost - in other words, memory for which accesses have an upper bound. Knuth's analysis still holds if certain pieces of memory are FASTER than the norm. If we take memory access going through swap as the normal, worst case, upper-bound cost of memory access, and RAM and cache hits as special better cases, the analysis still applies to the real world.

    Well, both atan() and += are "operations". But clearly a loop of N atans, while of the same polynomial complexity, will be orders of magnitude slower than a loop of N additions. This is because += is O(1) while atan() is O(nlogn) for some accuracy n iirc. Similarly, there's a complexity difference between accessing L1/L2 cache and accessing main memory over a shared bus. The two will never converge or cross; there is no data set size where atan() will outperform +=. To say that the former is a worst-case cost estimate for the latter is only correct in a discrete mathematical sense, for all practical purposes it's meaningless. An algorithm that can rely on addition will always be superior to one relying on atans, even if of the same complexity. In fact, even an O(nlogn) addition-based algorithm will be superior to an O(n) atan based one - the two will converge at infinity (assuming I'm correct about the complexity of atan), so for any finite (real-world) data set the former will be faster.

  53. Don't you think we should ask the guy? by symbolset · · Score: 1

    I know he's a legend and all (and most deservedly so!), but it's not like he's dead or anything. He's only 72. We could ask him.

    Before you ask your questions though, thank him - even if you don't know why. You owe him more than you know.

    --
    Help stamp out iliturcy.
    1. Re:Don't you think we should ask the guy? by JWSmythe · · Score: 1

        I tried once. All he said is "who the hell are you and"....

        Oh, someone already posted that joke. Sorry.

      --
      Serious? Seriousness is well above my pay grade.
  54. I can't wait by cromar · · Score: 1

    I can't wait to read the comments on this article. You can be sure of learning a lot. This is the kind of article I miss being featured on Slashdot more frequently.

  55. Re:Theoretical performance vs real-world performan by Anonymous Coward · · Score: 0

    The issue is that in the real world, the assumptions underlying the calculation of algorithmic complexity may not hold.

    Oh, finally reach chapter 2 in your CS 101 textbook, did you?

    This means that algorithms in the real world can scale worse than their theoretical "worst-case", if that theoretical worst-case scaling is based on the assumption of constant memory access cost, since that assumption does not hold in the real world.

    Hmmm, yes. Probability and statistics only tend to hold true as the sample size increases. This means that in any given single situation, it is nearly impossible to determine if the statistical predictions are going to be valid.
    And when your assumptions you base your analysis are wrong, then your predictions mean squat.

    Film at 11.

  56. Timer wheels don't scale by tlambert · · Score: 1

    Timer wheels don't scale

    This is somewhat counter-intuitive, but it is nonetheless true, if you are wanting to have a very large number of timers, such as if you wanted a large number of 2 MSL timers because you want to support a huge number of TCP connections.

    The problem is that given a number of buckets on the wheel, in order to cancel a timer, you have to either keep them as a doubly-linked list, or you have to run on average 50% of the buckets in the list. For timer lbolts, when the wheel turns to the next slot, you have to run the whole list and check each element to see if its expired, since you can't order the elements in the bucket in time-order to preclude the need to continue running when you hit the first non-expired timer. This is because the elements are (effectively) hashed onto the wheel slot. Even if you have buckets-by-magnitude, it's actually not good enough to represent every resolution equally.

    For things like the TCP 2 MSL timer wheels that are used in BSD4.4 and later, for scalability, you are better off going back to the BSD 4.3 tailq-list implementation so that you don't have to run all the entries; as previously noted, most timers are cancelled before they expire, so if the lists are ordered by increasing expiration interval (which they can be, for fixed interval values), your overhead then doesn't go up especially badly as your number of timers outstanding goes up.

    I've made this change to the TCP 2 MSL timer implementation at several companies, and got good scalability wins every time. One of those companies was Array Networks, and we sold a commercial reverse proxy cache similar to Varnish, although we did massive kernel work in order to scale it better (as in handling ~36,000 TCP connections a second).

    -- Terry

  57. The Myth of RAM by theunixman · · Score: 1

    I'm fairly certain that past a certain volume, keeping a significant fraction of requests resident in RAM is not actually possible. Consider sites serving up large media files that are constantly changing, and even with a fairly large budget having RAM to cache all of that content is not reasonable. It's not much larger when having sufficient spindles for naïve algorithms is also not an option.

    At this point having intelligent algorithms that understand non-uniform memory access patterns is essential, whether it's L1 - L2 cache, cache to SDRAM, RAM to disk, and even local disks to network storage. This is where algorithms like B*-tree and the B*-heap start to perform much better, since they're designed around such non-uniform memory access. Database engines also have been designing indexes around these principles for decades, although in a very specific way that's much more difficult to use generally.

    So while it may be comforting to throw out the RAM card and give up when the reality of budgets and billion-dollar-RAM-caching systems are unobtainable and give up, actually trying to solve the underlying problem is much more interesting.

  58. Re:Theoretical performance vs real-world performan by kcelery · · Score: 1

    There might be something to do with the Knuth bounty. The dollar value reward is not particularly high,
    but the Knuth reward check is some collector's item worth many time more than the face value.

  59. The smell of slashdot in the morning... by phkamp · · Score: 4, Informative

    What a misleading title, it is not even in the same continent as the article.

    A large number of people obviously didn't read the actual article.

    And I guess Knuth has quite a fanboi community on slashdot. I wonder if he really appreciates that ?

    Some of those who did read the article, does not seem to know the difference between a binary heap and a binary tree, and even the pretty strong clue to the difference in the text, did not make them go check wikipedia. 10 out of 10 for selfesteem, but 0 out of 10 for clue.

    Those who think CS should be unsullied by actual computers should make sure to note this belief on their resume. (Trust me, everybody you send your resume to will appreciate that.)

    Those who advocate getting rid of Virtual Memory must have much more money for RAM than is sensible. I wish I could afford that.

    About five comments tries, in vain it seems, to explain the point of my article to the unwashed masses (kudos!, but really, what are you doing here ?)

    Not one comment rises to a level where I feel a need to answer it specifically. On Reddit over the weekend there were about a handful.

    Is that really par for the course on slashdot these days ?

    Sic transit gloria mundi...

    Poul-Henning

    --
    Poul-Henning Kamp -- FreeBSD since before it was called that...
    1. Re:The smell of slashdot in the morning... by etymxris · · Score: 1

      Well the main complaint is that your work isn't anything new really. You seem to assume that CS has not progressed in 40 years, that no modern researchers are aware of tiered memory.

    2. Re:The smell of slashdot in the morning... by Anonymous Coward · · Score: 0

      The problem is not whether or not modern researchers are aware of tiered memory --- I'm sure they are. The problem is that most texts that cover algorithms don't discuss the effects of tiered memory on running time, and most students of computer science aren't taught them.

      The issue is that researchers have to find stuff to publish which is "interesting" by the definition of tenture committees and research sponsors (i.e., NSF, DARPA, the few companies still funding academic research, etc.) And stuff like this doesn't make the grade. Worse yet, the textbooks aren't talking about this sort of thing either, probably because they are written by academicians who don't think about these sorts of problems a lot because they need to do research that will keep them funded and get them tenure. So yes, they may know the fact that modern OS's page and swap, but that doesn't mean they've thought about the consequences of this behavior, and taught this to their students.

      There are similar problems to this all over. For example, try finding a CS algorithm textbook which talks about how to do efficient locking for B-trees. It's simply not taught in most schools, because it's not in the textbooks. As a result it's one of those things that practitioners in the field need to learn, usually as oral lore from an older colleague -- and that's a real shame, and IMHO, a real indictment regarding how CS is taught in this country.

    3. Re:The smell of slashdot in the morning... by etymxris · · Score: 1

      I get the impression that there is plenty of research on data structures and tiered memory. If no one had done it before, it'd be an easy thesis. What grad student wouldn't jump at that opportunity. Anyway, a cursory search gives examples like this:

      http://www.eecs.umich.edu/~jignesh/quickstep/publ/cci.pdf

      As for pedagogy, you're probably right that more focus needs to be put on the effects of tiered memory on various data structures.

    4. Re:The smell of slashdot in the morning... by ixache · · Score: 1

      Wow ! Your post is full of amusing self-references. Let me me point them out for the "unwashed masses" that have now come to populate this very site, Slasdot.

      What a misleading title, it is not even in the same continent as the article.

      I mean, having a title as benign as "You're Doing It Wrong", what could go wrong, indeed. I mean, people and their hyperboles!

      A large number of people obviously didn't read the actual article.

      You're new here, aren't you?

      And I guess Knuth has quite a fanboi community on slashdot. I wonder if he really appreciates that ?

      Yeah, the grapevine has it that he's become complacent, reveling in fan adoration, procrastination, undecision and maybe various drug abuse (but what will not old age excuse?), leaving him unable to finish or abandon his major opus that he began more than forty years ago... Maybe he needs counsel about what to do from Brian Wilson, or maybe some coder luminary?

      Some of those who did read the article, does not seem to know the difference between a binary heap and a binary tree, and even the pretty strong clue to the difference in the text, did not make them go check wikipedia.

      I know of someone else who could have checked Wikipedia about cache-aware/oblivious algorithms...

      10 out of 10 for selfesteem, but 0 out of 10 for clue.

      I have a feeling your own self-esteem goes up to eleven.

      Those who think CS should be unsullied by actual computers should make sure to note this belief on their resume. (Trust me, everybody you send your resume to will appreciate that.)

      And what about those who thinks they can shoot from the hip computer scientists without spending half on a hour researching prior art in their favourite search engine? Especially when said research matter has been opened for at least a decade, is taught in the Introduction of Algorithms course (as "advanced subject") at the very unconspicuous, fly-by-night operation known as "MIT" (I mean, academic institutions located in a "Cambridge" city in the USA? So obviously a scam to part the gullible students from their tuition money!), and even referenced in the eponymous text book (3rd ed. at least), also very unconspicuous. And I'm not going to google it for you, I'm sure you can learn to do it yourself.

      Not one comment rises to a level where I feel a need to answer it specifically.

      Particularly the ones showing you wrong or not as original you think you are.

      Sic transit gloria mundi...

      At least you seem to be getting better at latin citations... True, it's not that difficult with this newfangled IntraWebs. You should try it sometimes.

      Now don't get me wrong, I'm just having a bit of bad fun here. Abyssus abyssum invocat, I guess.

      Nevertheless, I have to say that you've deservedly gained your status as a hero coder, whereas I'm a nobody from the IntraWebs, and even I can tell that your article is interesting and informative.

      But you sure have a way to come across as an overly obnoxious guy with a chip on his shoulder, and not as a guy who could have a paper accepted in a peer-reviewed publication. And one wonders when hero coders get a bad rap...

      YMMV, some restrictions apply, and all that jazz.

      Xavier

      --
      Do I make sense? Please report if not.
    5. Re:The smell of slashdot in the morning... by fishexe · · Score: 1

      Those who think CS should be unsullied by actual computers should make sure to note this belief on their resume. (Trust me, everybody you send your resume to will appreciate that.)

      "Computer Science is no more about computers than astronomy is about telescopes." --Edsger Dijkstra

      --
      "I don't care about the Constitution!" --Bill O'Reilly, November 17, 2009
  60. Even Microsoft knows this. by Anonymous Coward · · Score: 1, Informative

    http://research.microsoft.com/en-us/um/people/trishulc/papers/cache-conscious.pdf

  61. Small "correction"... apk by Anonymous Coward · · Score: 0

    This needs a "small bit of correction" (or does it?)

    "2.) Then, send each potential child node off to where they belong comparing to nodes as you go, & placing "smaller-than-compared-to-potential parent" child node candidate item to left of said "potential parent/compared-to" node, & larger child node candidate off to right of said "compared-to potential parent" node possible, in order to place child nodes off parents, etc./et al though." - by Anonymous Coward on Monday June 14, @10:18PM (#32574034)

    The bolded portion quoted from my original post actually SHOULD go the opposite, as follows:

    smaller-than-compared-to-potential parent" child node candidate item to RIGHT of said "potential parent/compared-to" node, & larger child node candidate off to LEFT of said "compared-to potential parent" node possible, in order to place child nodes off parents

    (There! Corrected my own "mistake", before anyone else did...)

    APK

    P.S.=> Thing is though - do you HAVE to put the smaller child elements to the RIGHT of any parent node item and the larger child elements to the LEFT of any parent node item? I have always wondered IF you could do the opposite and get away with it, and also have it work just fine?? It makes sense to me you actually COULD! apk

  62. Just an improvement on a bad programming technique by internet-redstar · · Score: 1
    Basically he starts out with doing the wrong thing and improves it:

    Allocating too much memory in userspace so the system starts swapping.
    And then he comes up with a more efficient way to use the often swapped in and out memory pages.

    Better programming is: keep all the junk you need quick in real memory, leave enough space for filesystem caching as well and prevent the OS from most swap activity.

  63. Re:Just an improvement on a bad programming techni by etymxris · · Score: 1

    3 machines with 16GB RAM is much cheaper than 1 machine with 300GB RAM. There's nothing wrong with using swap if you do so wisely.

  64. Re:Just an improvement on a bad programming techni by Anonymous Coward · · Score: 1, Informative

    3x16 = 48, not 300.

    But I understand what you want to say.

    But if the performance of your app is based upon having a lot of swap activity, you should do it wisely.

    Allocating too much and resorting to 'let the OS sort it out' is not the best approach, which leaves space for optimisation. This is such an optimisation.

    But better programming would be to ensure the system doesn't swap at all or at a very low swapin swapout rate.

  65. Re:Theoretical performance vs real-world performan by prockcore · · Score: 1

    A cache miss isn't just "slower" it flushes the cache and affects subsequent memory access speeds. Thus O(n) can become O(n^2).

  66. available by fireylord · · Score: 1

    Well actually 2 copies would lock 96% of starting available memory. I believe the key word is available,
    unless of course you're trying to make a funny and it somewhat overshot the mods of course.

  67. Heh, funny part is? I dislike PERL by Anonymous Coward · · Score: 0

    "Ok Kids, come a bit closer! Here you can see the effects of long-term Perl misuse. Horrible, isn't it?
    No need to be afraid, it's strong glass he's behind.
    - by Anonymous Coward on Tuesday June 15, @05:23AM (#32575746)

    Per my subject-line above, I actually dislike PERL for "web-work", AND, for system scripting as well (though I do think that CGI bins are safer than javascript work, while doing webpages @ least, but also much slower too typically). Regular expressions work is difficult imo, even with a book helping you is why...

    APK

    P.S.=> If you thought that the post of mine you had responded to was "bad" or "too techno"? Try my other one on for size here -> http://developers.slashdot.org/comments.pl?sid=1686094&cid=32574034 ... apk

    1. Re:Heh, funny part is? I dislike PERL by Anonymous Coward · · Score: 0

      I'd say the GP is referring to your use of the English language, rather than the Perl language..

  68. Re:Just an improvement on a bad programming techni by mr_gorkajuice · · Score: 1

    3x16 = 48, not 300. But I understand what you want to say.

    I suspect you don't. The point is that TFA mentions 300GB VM, on a machine with 16GB physical RAM.
    Three such machines might match one machine with 300GB physical RAM, at a much lower price.
    3x16 is irrelevant.

  69. I don't think so. by LWATCDR · · Score: 1

    "Unless you have many servers, it is cheaper to throw money at the problem in the form of physical RAM before you start thinking about problems like this."
    You are thinking just about a single instance. You may be right for a single instance but that is not the right way to think about writing code.
    If his performance claims are true then this is well worth it. He used this in a web proxy. The first place that used this web proxy saved no less then 75% of the resources needed for the task.
    Multiply that by however many people can use that proxy and you get a lot of savings in power used and machines needed to get the same task done.
    This is one of the great but often under achieved potentials in FOSS. Hopefully this can be applied to other tasks. Maybe even in the STL.
    Once that happens you have a classic case of "a rising tide lifts all boats."
    This kind of optimistically is exactly what should be done. The enter idea behind first structured and now OOP is code reuse. That ideal really is or should be at the heart of FOSS and frankly of CS in general.

    --
    See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
  70. Knuth took his own sweet time by tepples · · Score: 1

    46 years is a long time in CS.

    During which time Knuth could have put out volume 4 a little quicker, explaining the effects that memory hierarchy has on the algorithms of previous volumes.

    1. Re:Knuth took his own sweet time by Anonymous Coward · · Score: 0

      Knuth is all talking about how many repetitions some algorithm takes, not absolute time. You really need some standard way to evaluate algorithms, and Knuth still has best approach for this. Number of cycles is only absolute generic performance for some algorithm.

      For real world implementation you take this theoretical performance and multiply each operation with real hardware latency. Because all these multi-level caches, pre-emption and so on, this is usually too much work to calculate. So people just measure total running time for algorithms for real implementations.

      Sorry boys, Knuth is still right. You really need to take your CS courses...

  71. ...and who are you calling a dumb Knuth? by syousef · · Score: 1

    Or is it a stupid Knuth?

    --
    These posts express my own personal views, not those of my employer
  72. Re:Theoretical performance vs real-world performan by DragonWriter · · Score: 1

    But everyone already knows that (or should). Knuth knows that as well, caches and paging systems are not unknown things to him.

    I agree. In GP I was clarifying what the issue was, not defending the idea in the TFS headline that "Knuth was wrong". A more accurate (though less headline-worthy) title would be "A naive reading of Knuth may be more misleading than most people are aware."

  73. Facepalm by rakslice · · Score: 1

    It's not a very useful heap if it has the middle value at the top.

    http://en.wikipedia.org/wiki/Heap_(data_structure)

  74. I'm obviously a little thick by rakslice · · Score: 1

    As usual, Hacker News had it 1) first 2) correct and 3) full of comments from people who obviously RTFA.

    So perhaps someone can tell me why I still read Slashdot?

  75. Algorithm used here in /. by hlee · · Score: 1

    According to the article Slashdot uses an HTTP cache called Varnish, which uses the B-heap. Can any /. ed/admin comment on how effective it is?

    Also, this idea seems similar to the locality optimizations proposed in algorithms like merge sort http://en.wikipedia.org/wiki/Merge_sort#Optimizing_merge_sort.

  76. It's a BINARY heap (not std. heap rakslice) by Anonymous Coward · · Score: 1, Interesting

    See this:

    http://en.wikipedia.org/wiki/Binary_heap

    "It's not a very useful heap if it has the middle value at the top." - by rakslice (90330) on Tuesday June 15, @01:09PM (#32580468) Homepage

    See that URL at the top, because what's noted in this article is NOT a "std. heap", but instead, a BINARY heap... & it IS built up from a BINARY TREE structure!

    Additionally, those ARE basically constructed in the manner I noted doing comparisons of each "potential parent node" to it's "potential children node(s)" beneath it, usually using "Greater than" or "Less than" type comparisons & putting items to the left & right of said "potential parent node(s)". IN fact, see this from that same URL on BINARY HEAPS:

    http://en.wikipedia.org/wiki/Binary_heap

    "The heap property: each node is greater than or equal to each of its children according to some comparison predicate which is fixed for the entire data structure."

    (Just like a Binary Tree is constructed & as I noted in my orig. post)

    The "pertinent quote" from said Wiki is this:

    http://en.wikipedia.org/wiki/Binary_heap

    A binary heap is a heap data structure created using a binary tree.

    (And, what do BINARY trees need? A pivot, like many sorts do, and that is usually the "mid-most value", because "binary search patterns", depend on that...)

    Hence, why I noted to use my "puny trick" IF NEEDED (not always needed, as for instance in DB work, rowcounts in datasets ARE available), to find said PIVOT midpoint value IF you do not know the total # of elements in your dataset beforehand (or, if it changes, such as values being eliminated during say, deduplications of elements/records of said dataset & say, DB style indexing + reindexing is NOT in place in your app)...

    APK

    P.S.=> However, I did state "correct me if I am 'off'" in my first post, so "have @ it" guys (as rakslice has attempted to do, but, he used a std. heap NOT what this article's about in BINARY heaps usage)!

    (Here? I am PRETTY SURE I am correct, but, I can stand new ideas & corrections as much as the next guy can @ times & though I have worked with Binary Trees more than a few times? Binary Heaps I have not, so... keep those "critiques" coming if you wish!)

    So again: "have @ it" with the critiques, especially in material of this nature & the fact I have not "visited it" in QUITE SOME TIME (it's the FUN stuff imo!)... apk

  77. Re:Theoretical performance vs real-world performan by azmodean+1 · · Score: 1

    You actually have it backwards. With a finite n, it's completely up in the air which one is faster, since constant factors may outweigh the O() complexity. It's only as n approaches infinity that you can say for certain that O(n) will be faster than O(nlogn). That is the point the GP is making.

    Also assuming you have operations that are O(1) and O(nlogn), and algorithms that are O(nlogn) and O(n) respectively, the "addition-based" algorithm is asymptotically faster (they will NOT converge), but that isn't the case in your example, it's actually O(1) and O(mlogm) (an independent input m), so for a bounded value of m, the O(nmlogm) may very well be faster than O(nlogn).

    The fundamental problem here is a mixing of concerns, the memory access speed has no affect whatsoever on the computational complexity of the algorithm, which is all that classical big-Oh notation addresses. I wouldn't be at all surprised to find that modern notation has a standard way to denote special costs of operations, but if someone says "algorithm x is O(nlogn)", it is understood to mean idealized computational complexity based on the number of operations performed. If you feel like modeling things like number of IO operations as part of the complexity analysis, that is perfectly valid, but it doesn't invalidate the idealized representation of it's complexity.

    Put another way, "Quicksort" has a complexity of O(nlogn) no matter what its set size is or what the operations cost, it doesn't matter that for most values of n the function is not computable, or that a particular comparison operation may take 5.6 millennia to compute, the complexity is still O(nlogn).

  78. Is this the "english grammar" section of /.? by Anonymous Coward · · Score: 0

    "I'd say the GP is referring to your use of the English language, rather than the Perl language.." - by Anonymous Coward on Tuesday June 15, @05:15PM (#32583570)

    Per my subject-line above also, IS THERE SUCH A SECTION OF THIS FORUMS, and do YOU have a PHD to your name/credit in English? No?? Get back to us when you do have one, because you & yours are obviosly illiterate or you forgot to take your Dyslexia meds/treatments/therapies (whatever) or ADD/ADHD meds!

    Plus, your lack of a PHD in English to your credit/name doesn't exactly qualify you & your kind ("writing style critique slinging trolls") as experts in English yourselves.

    (OR, alternately? Well - Perhaps there ought to be so "wannabe PHD's in English" (minus the PHD to their credit/name of course) have a "raison d'etre" around here, other than being the trolls you clearly are)...

    APK

    P.S.=> Of course, there IS the alternate, & that would be to get them a "hooked on phonics" remedial reading course for you & yours, so you're able to read properly as well!

    As to your opinions? Opinions on my "writing style" clearly vary!

    I.E.-> I have a truckload of upwards mods around here, shown below (AND, as an AC no less, which is FAR MORE DIFFICULT to get those for we AC's, because /.'s default javascript &/or IE model is to list AC posts as "hidden", to bury them as some "inducement" to register... no thanks, that just makes folks EASILY tracked sheep for trollers like you "wannabe PHD" types, lol!).

    Oh, the list of my upmods? Ok sure (these are those who disagreed with the "likes of your kind"):

    +5 'modded up' posts by "yours truly" (4):

    http://it.slashdot.org/comments.pl?sid=1139485&cid=26975021

    http://it.slashdot.org/comments.pl?sid=1139485&cid=26974507

    http://it.slashdot.org/comments.pl?sid=170545&cid=14210206

    http://hardware.slashdot.org/comments.pl?sid=175774&cid=14610147

    ----

    +4 'modded up' posts by "yours truly" (4):

    http://slashdot.org/comments.pl?sid=161862&cid=13531817

    http://developers.slashdot.org/comments.pl?sid=167071&cid=13931198

    http://tech.slashdot.org/comments.pl?sid=1290967&cid=28571315

    http://tech.slashdot.org/comments.pl?sid=1461288&cid=30273506

    ----

    +3 'modded up' posts by "yours truly" (5):

    http://developers.slashdot.org/comments.pl?sid=155172&cid=13007974

    http://it.slashdot.org/comments.pl?sid=166850&cid=13914137

    http://slashdot.org/comments.pl?sid=175857&cid=14615222

    http://slashdot.org/comments.pl?sid=273931&threshold=1&commentsort=0&mode=thread&cid=20291847

    http://it.slashdot.org/comments.pl?sid=1021873&cid=25681261

    ----

    +2 'modded up' posts by "yours truly" (25):

    http://it.slashdot.or

  79. Ah, a patented "/. ad hominem attack", lmao! by Anonymous Coward · · Score: 0

    "Nobody cares about your shitty posts..." - by Jizzbug (101250) on Wednesday June 16, @11:06AM (#32590744)

    Hmmm, well, "opinions vary", & quite clearly, per this list from /. posters alone rating up my posts here many, Many, MANY times, see below...

    That's only a SMALL PARTIAL LIST below also, no less, & with myself as an AC poster no less, which does make it more difficult to get "mod ups" really, because /.'s default format is to make AC posts "hidden posts", burying them (or making them be ignored)).

    So, does being an "almighty (not, lol), 'registered user' elitist wannabes" who're part of the 'in-crowd' here or elsewhere any smarter/more intelligent & knowledgeable than us AC's?

    No.

    What it DOES do, however & by way of contrast/comparison, is make YOU all the more "trollable" & trackable via your posting history here (far better than a GOOGLE search for instance would, & that means you are 2x as trackable as us AC's are). Plus, I "blow by" the unfair/unjust "10 posts per 24 hours" limit imposed on AC's, in seconds (literally, without loss of speed like proxies or TOR nail you with)...

    The list I noted above? "Here 'tis:"

    "My Name is Ozymandias: King of Kings - Look upon my works, ye mighty, & DESPAIR..."

    ----

    Windows NT Magazine (now Windows IT Pro) April 1997 "BACK OFFICE PERFORMANCE" issue, page 61

    (&, for work done for EEC Systems/SuperSpeed.com on PAID CONTRACT (writing portions of their SuperCache program increasing its performance by up to 40% via my work) albeit, for their SuperDisk & HOW TO APPLY IT, took them to a finalist position @ MS Tech Ed, two years in a row 2000-2002, in its HARDEST CATEGORY: SQLServer Performance Enhancement).

    WINDOWS MAGAZINE, 1997, "Top Freeware & Shareware of the Year" issue page 210, #1/first entry in fact (my work is there)

    PC-WELT FEB 1998 - page 84, again, my work is featured there

    WINDOWS MAGAZINE, WINTER 1998 - page 92, insert section, MUST HAVE WARES, my work is again, there

    PC-WELT FEB 1999 - page 83, again, my work is featured there

    CHIP Magazine 7/99 - page 100, my work is there

    GERMAN PC BOOK, Data Becker publisher "PC Aufrusten und Repairen" 2000, where my work is contained in it

    HOT SHAREWARE Numero 46 issue, pg. 54 (PC ware mag from Spain), 2001 my work is there, first one featured, yet again!

    Also, a British PC Mag in 2002 for many utilities I wrote, saw it @ BORDERS BOOKS but didn't buy it... by that point, I had moved onto other areas in this field besides coding only...

    Lastly, being paid for an article that made me money over @ PCPitstop in 2008 for writing up a guide that has people showing NO VIRUSES/SPYWARES & other screwups, via following its point, such as THRONKA sees here -> http://www.xtremepccentral.com/forums/showthread.php?s=ee926d913b81bf6d63c3c7372fd2a24c&t=28430&page=3

    ----

    What do I have to say about that much above? I can't say it any better, than this was stated already (from the greatest book of all time, the "tech manual for life" imo):

    "But by the grace of God I am what I am: and his grace which was bestowed upon me was not in vain; but I labored more abundantly than they all: yet not I, but the grace of God which was with me." - Corinthians Chapter 10, Verse 10

    (And, because I got LUCKY to have been exposed to some really GREAT classmates, professors, & colleagues on the job over time as well)

    ====

    +5 'modded up' posts by "yours truly" (4):

    http://it.slashdot.org/comments.pl?sid=1139485&cid=26975021

  80. Are you serious? Do you even know how to read? by fishexe · · Score: 1

    article summary:

    "disk is slower than RAM. some doofs don't realize their system is swapping. ergo algorithm is bad."

    Poul-Henning is definitely not a "doof"...To suggest that phk doesn't know what he's talking about is absurd.

    Dude, chill. Nobody called Poul-Henning a doof. They only paraphrased him as calling other people doofs, namely those people who blindly follow Knuth's algorithm without checking whether its assumptions apply to their modern situations. If such people are doing professional software development, I would also call them doofs. Everybody acknowledges phk's all-knowingness, but some people were criticizing the headline by kdawson. Nothing to see here, move along.

    --
    "I don't care about the Constitution!" --Bill O'Reilly, November 17, 2009
  81. To watch yourself "get it wrong" Facepalm by Anonymous Coward · · Score: 0