You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Johan Oskarsson <jo...@oskarsson.nu> on 2007/01/21 16:59:10 UTC
Best practice for in memory data?
Hi.
Currently some of my map reduce jobs need quick access to additional
data to check some input values in the map phase.
This data is currently held in memory in a hashmap. It's very quick but
as each job starts several jvms the data will be held in memory multiple
times. It will also mean I have to increase the memory each task uses.
This in turn leads to out of memory problems if too many memory
intensive tasks are run resulting in the job being lost.
One alternative would be to use a mapfile, but they're obviously much
slower. The solution I'm considering is to use a hashmap
as the in memory cache and a mapfile as the underlying data source.
I've read the javadoc on DistributedCache, but that seems to only deal
with distributing the actual data, not on how to do fast reading from it.
Any advice on how to solve this problem?
Would it be possible to somehow share a hashmap between tasks?
A big thanks to the hadoop team for the hard work they put into this.
/Johan
Re: Best practice for in memory data?
Posted by "Bryan A. P. Pendleton" <bp...@geekdom.net>.
There's also code floating around for a Multithreaded MapRunner. This (with
appropriate synchronization) would allow a shared HashMap without having to
pay the per-simultaneous-map overhead.
Another thing that might or might not make sense would be to use memcached
for your hashtable. This may or may not be an appropriate solution for your
problem, depending on scaling, your switches, and your access patterns. But,
it's probably worth a try. You should even be able to use the existing
bin/slaves.sh to launch a bunch of memcached instances quickly across your
cluster.
On 1/25/07, Doug Cutting <cu...@apache.org> wrote:
>
> Johan Oskarsson wrote:
> > Any advice on how to solve this problem?
>
> I think your current solutions sound reasonable.
>
> > Would it be possible to somehow share a hashmap between tasks?
>
> Not without running multiple tasks in the same JVM. We could implement
> a mode where child tasks are run directly in the JobTracker's JVM, but
> that would not be good for reliability. Alternately we could have
> spawned child processes execute multiple tasks, perhaps even in
> parallel, extending the TaskUmbilicalProtocol(), JobTracker, etc. This
> would unfortunately not be a trivial modification.
>
> Doug
>
--
Bryan A. P. Pendleton
Ph: (877) geek-1-bp
Re: Best practice for in memory data?
Posted by Doug Cutting <cu...@apache.org>.
Johan Oskarsson wrote:
> Any advice on how to solve this problem?
I think your current solutions sound reasonable.
> Would it be possible to somehow share a hashmap between tasks?
Not without running multiple tasks in the same JVM. We could implement
a mode where child tasks are run directly in the JobTracker's JVM, but
that would not be good for reliability. Alternately we could have
spawned child processes execute multiple tasks, perhaps even in
parallel, extending the TaskUmbilicalProtocol(), JobTracker, etc. This
would unfortunately not be a trivial modification.
Doug
Re: Best practice for in memory data?
Posted by Andrzej Bialecki <ab...@getopt.org>.
Johan Oskarsson wrote:
> Hi.
>
> Currently some of my map reduce jobs need quick access to additional
> data to check some input values in the map phase.
>
> This data is currently held in memory in a hashmap. It's very quick
> but as each job starts several jvms the data will be held in memory
> multiple times. It will also mean I have to increase the memory each
> task uses. This in turn leads to out of memory problems if too many
> memory intensive tasks are run resulting in the job being lost.
>
> One alternative would be to use a mapfile, but they're obviously much
> slower. The solution I'm considering is to use a hashmap
> as the in memory cache and a mapfile as the underlying data source.
>
> I've read the javadoc on DistributedCache, but that seems to only deal
> with distributing the actual data, not on how to do fast reading from it.
>
> Any advice on how to solve this problem?
> Would it be possible to somehow share a hashmap between tasks?
Here's two practical tips:
* instead of a HashMap you could use a trie, e.g. a prefix trie (there
is an implementation of this in Nutch). If values are short I load them
directly to a trie, if they are long I compute a hash (e.g. minimal
perfect hash) and store only hashes in a trie.
* for some types of problems (mostly when wanted values are a small
subset of all possible input values) I use Bloom filters to quickly
check if the current value is likely to match, and then consult a trie,
or in the worst case I check this with an external MapFile. However, if
the current value is absent in the Bloom filter I don't have to check
anything, which is a win.
Hope this helps ...
--
Best regards,
Andrzej Bialecki <><
___. ___ ___ ___ _ _ __________________________________
[__ || __|__/|__||\/| Information Retrieval, Semantic Web
___|||__|| \| || | Embedded Unix, System Integration
http://www.sigram.com Contact: info at sigram dot com