News for hackers. Stuff that matters.
Re:What are Bloom filters? (2015) by s_q_b on Friday August 05, 2016 @11:43AM (#12233162)
Bloom filters are beautiful and highly underutilized.

I used a Bloom filter in an interview and they looked at me like it was some form of arcane sorcery.

Isn't this standard in algorithms and data structures courses? Does anyone know if it has been removed from the curriculum?

Re:What are Bloom filters? (2015) by Retric on Friday August 05, 2016 @12:04PM (#12233353)
Bloom filters have a lot of problems for critical processes in practice. They are best used when being wrong is a non issue or as a type of cache, but preforming a hash is generally really slow. Also, the way virtual memory works looking up an answer often makes storing the new value much faster.

So, while cool they have generally been replaced by far more useful and less complex topics.

One example is if your looking for duplicates among huge data sets. You farm out your Filter to 1,000 machines merge them, then re run to get a list of possible collisions. Then compare that list. But, well merge sort can do the same thing a little slower, it's a rare problem, and the pathological case for Bloom filters is really bad. So, even if you know about Bloom filters you may go with the simpler idea and be done sooner.

PS: In that example hash speed might mean sorting is actually faster.

Re:What are Bloom filters? (2015) by jedberg on Friday August 05, 2016 @01:05PM (#12233978)
The place where bloom filters really shine is doing lookups on data where most of the time the data isn't there.

For example, when you load a page on reddit, it has to check for a vote on every single comment on the page to see if you voted on it. Chances are 99% of the time you didn't vote on an item. Using the built in bloom filter in Cassandra, it can very quickly tell if you voted on an item without having to hit the data store most of the time, which saves a ton of time.

(As a side note, there is an extra optimization that makes things even faster -- reddit tracks the last time you voted on anything as an attribute of your user, so if the page is newer than your last vote, it just assumes you couldn't have possible voted on it, skipping the lookups altogether).

Re:What are Bloom filters? (2015) by Retric on Friday August 05, 2016 @01:41PM (#12234292)
A list of votes per user per page would also work. ~90% of the time that list would be empty, if it's not your likely going to eventually need to know which specific items where voted on so might as well just load them all.

Further, voting records are just not that big a data structure. Sure, it's much better than a poor implementation and might be a great optimization to bolt onto a different design, but again it's niche with minimal befits when starting from scratch.

Edit: Now, I really want to know how they actually do this.

Re:What are Bloom filters? (2015) by jedberg on Friday August 05, 2016 @03:54PM (#12235308)
> A list of votes per user per page would also work. ~90% of the time that list would be empty,

Not really. People tend to vote on one or two things on a page. So you'll have a long list of people who voted on one or two of the 1000+ items, and now you've had to do an extra lookup.

It's a lot faster to just go straight for the votes and take advantage of the bloom filter.

Re:What are Bloom filters? (2015) by Retric on Friday August 05, 2016 @07:10PM (#12236290)
Real world data wins so if you have real data then great a write up would be cool.

However, it's 100% empty the first time someone opens a link. If someone up votes there is no need to refresh, so they need to up vote and then refresh the page which I assume is less common. With lot's of pages that never get refreshed and a long tail of pages people go back to. So, my assumption is you can easily keep a vote list in memory for popular pages and everything else is basically a non issue.

As to matching up votes with items, I kind of think that's for client side JavaScript in most cases.

Re:What are Bloom filters? (2015) by zardeh on Friday August 05, 2016 @05:26PM (#12235847)
You work(ed) at reddit, d(o|idi)n't you?
Re:What are Bloom filters? (2015) by jedberg on Friday August 05, 2016 @07:57PM (#12236434)
Worked, yes.
Re:What are Bloom filters? (2015) by zardeh on Friday August 05, 2016 @02:28PM (#12234702)
>A list of votes per user per page would also work. 90% of the time that list would be empty, if it's not your likely going to eventually need to know which specific items where voted on so might as well just load them all.

How? This means you're now duplicating data, instead of organizing as

page has comments have comments have ... have votes

you now have

page has comments have comments have ... have votes page has list of special comments where you don't know where they are or what their parental hierarchy is and still need to look up in the list anyway.

you're duplicating the "has been voted on" field.

Re:What are Bloom filters? (2015) by Retric on Friday August 05, 2016 @02:44PM (#12234830)
> How?

Page has a list of people who have voted, and that list points to a list of their votes. Each comment has a a number for vote counts, but not a list of scores.

User opens page, they get a list of comments with scores. And a possibly empty list of votes. 99.9% is probably less than 20 votes from that user so 160 bytes or less. Worst case is what 8 byte comment ID * 1,000 up-votes = 8k.

On user vote, server looks at past votes on page and adds it if missing then updates comment score.

Ok, you need every vote from each user and caching comment scores is really likely a no brainier, but I guess you could recalculate it.

PS: Not all comments are going to be loaded, but again if your sending <200 bytes for the full list 99.9% of the time then doing something else has limited value.

Re:What are Bloom filters? (2015) by zardeh on Friday August 05, 2016 @05:23PM (#12235838)
But that requires like entirely rearchitecting the reddit backend to be less efficient.

A page has comments a comment has comments a comment has votes a vote has a user

That is to say that a vote is a many to many join from user-comment.

To do what you want, you'd also have to give the page the concept of "people who have voted on a comment that belongs to be or one of my children"

>User opens page, they get a list of comments with scores. And a possibly empty list of votes. 99.9% is probably less than 20 votes from that user so 160 bytes or less. Worst case is what 8 byte comment ID * 1,000 up-votes = 8k.

The problem isn't sending additional data over the wire, its that, say I've voted on 500 things on a page, then we're at 250,000 operations (for each comment check if its in my list of voted on comments), whereas a bloom implementation is O(n). And also the whole making your database structure repetative and icky.

Re:What are Bloom filters? (2015) by Retric on Friday August 05, 2016 @07:18PM (#12236328)
In your approach comments have votes the server must check the bloom filter for each comment then do a fetch for each match in the case of 500 votes that's 500 fetches which are at least votes * (log comments votes) because you can't trust the filter.

My approach that's client side most of the time. Further it's O (n) to compare matches between two sorted lists so just sort them in O (n log n). Further log 500 is faster than most hashes.

And of course for the most common case of no votes it's a single lookup and done.

PS: As to changing the back end, yes if the initial implementation is bad then you might have a point. But, again fixing the problem also works and produces far less code to maintain.

Re:What are Bloom filters? (2015) by nitrogen on Friday August 05, 2016 @02:25PM (#12234676)
At Reddit's size, wouldn't that just shift the problem from looking up votes to looking up lists? Millions of users times millions of articles? Seems like a fast way to get an early "no" would still be useful.
Re:What are Bloom filters? (2015) by Retric on Friday August 05, 2016 @03:03PM (#12234969)
Your looking it up once per page vs. once per comment. So, yes it might be faster, but when something takes 1% of total time speeding it up has massive diminishing returns.
Re:What are Bloom filters? (2015) by nitrogen on Friday August 05, 2016 @05:12PM (#12235782)
Still, 1% of a very large number (I don't know Reddit's server costs) can be a large enough number to be worth pursuing.
Re:What are Bloom filters? (2015) by Retric on Saturday August 06, 2016 @07:00AM (#12237713)
Agreed, HN uses 1 server and /. had 4 so I assume Reddit is of a similar size, but if they need a bunch of HW then sure it might be useful.
Re:What are Bloom filters? (2015) by hinkley on Friday August 05, 2016 @04:03PM (#12235371)
Shouldn't this be a problem we can apply SSE or other vector operations to? It seems like an insufficiently explored avenue.
Re:What are Bloom filters? (2015) by greenleafjacob on Saturday August 06, 2016 @02:26AM (#12237290)
Stable bloom filters are a nice variant with a less bad pathological case.
Re:What are Bloom filters? (2015) by dmoy on Friday August 05, 2016 @11:52AM (#12233245)
It is not standard, and was never added to most uni programs in the first place.
Re:What are Bloom filters? (2015) by chrisseaton on Friday August 05, 2016 @11:48AM (#12233210)
> Does anyone know if it has been removed from the curriculum?

I don't think there is such a thing as a single curriculum taught by all colleges that it could have been removed from.

Re:What are Bloom filters? (2015) by s_q_b on Friday August 05, 2016 @12:03PM (#12233344)
I'm speaking more of generalized educational practice than standardized curricula.
Re:What are Bloom filters? (2015) by hinkley on Friday August 05, 2016 @12:15PM (#12233463)
I do believe you specifically asked:

Isn't this standard in algorithms and data structures courses?

And the answer was 'no'.

It's okay to be publicly wrong. You wanted to learn something and now you know. But acting like you didn't ask it because you're feeling self-conscious just makes the whole thing awkward for everybody.

Re:What are Bloom filters? (2015) by nitrogen on Friday August 05, 2016 @02:21PM (#12234655)
I certainly didn't get the impression that the OP's follow-up comment was trying to cover up a public display of ignorance. Rather it seemed to me that the comment about lacking a centralized curriculum was needlessly snarky and did not interpret the OP's comment charitably.
Re:What are Bloom filters? (2015) by hinkley on Friday August 05, 2016 @04:01PM (#12235354)
I... mis-parsed the reply as saying that bloom filters haven't been part of a curriculum from which to remove it, and took it as a dig at the lack in CS curricula (which sentiment I would empathize with).

When Google first brought it to light I know most of the people I had access to had never encountered Bloom Filters in their college carreers. I can think of a handful of other things we 'should have learned' in school that just never came up (and I'm not even talking about practical skills, just theory).

Apologies for the mixup. Interesting to see the mix of up- and down-votes I got from this one. I wonder if some people made the same mistake I did...

Re:What are Bloom filters? (2015) by chrisseaton on Friday August 05, 2016 @02:35PM (#12234770)
My comment was genuinely trying to help explain that there isn't a single curriculum! I didn't post the telling off that followed his response!
Re:What are Bloom filters? (2015) by s_q_b on Friday August 05, 2016 @02:49PM (#12234863)
Fully agreed. Your comment was a fair question for clarification of what I meant by "curriculum". I thought I answered it fairly by clarifying that I meant topics generally covered by most universities in their in algorithms and data structures courses.

I'm not sure of the reason for the snark in the follow up. It was a fairly straightforward question and answer.

Re:What are Bloom filters? (2015) by nitrogen on Friday August 05, 2016 @03:00PM (#12234936)
You are quite right. I must have conflated the tone of one comment and the text of the other in my mind when I was replying.
Re:What are Bloom filters? (2015) by bostonpete on Friday August 05, 2016 @01:30PM (#12234184)
> Isn't this standard in algorithms and data structures courses?

It's not in my Cormen, Leiserson, & Rivest book, though my copy's nearly 20 years old so it could have been added in a later edition.

Re:What are Bloom filters? (2015) by hinkley on Friday August 05, 2016 @04:02PM (#12235362)
Did you go to MIT, or did you, like me, attend a college that copied MIT?
Re:What are Bloom filters? (2015) by bostonpete on Friday August 05, 2016 @05:14PM (#12235795)
I didn't attend MIT -- why do you think it's copying MIT, because it's from MIT press? I believe that's the closest thing there is to a "standard" algorithms textbook but things may have changed since my college days...
Re:What are Bloom filters? (2015) by gf263 on Friday August 05, 2016 @12:33PM (#12233650)
It's taught in the intro data structures course at Queen's University in Ontario. Really cool stuff.
Re:What are Bloom filters? (2015) by the8472 on Saturday August 06, 2016 @03:21AM (#12237383)
Bittorrent uses them for distributed calculation of statistics. For counting of set unions specifically.

http://bittorrent.org/beps/bep_0033.html#abstract

Re:What are Bloom filters? (2015) by SamHealer on Friday August 05, 2016 @01:00PM (#12233920)
It was covered in our DSA unit, at least when I took it a couple years back.