You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mahout.apache.org by Gabor Bernat <be...@primeranks.net> on 2013/04/23 00:22:08 UTC
Mahout Similarity Caching
Hello,
I'm using Mahout in a system, where the typical response time should be
below 100ms. I'm using an item based recommender with float preference
values (with Tanimato similarity for now, which is passed into a
CachingItemSimilarity objec for performance reasonst). My model has around
7k items, 26k users with around 100k preferences linking them.
Instead of performing a recommendation, I only need to estimate preferences
of the user for around 3-4k items (this is important, as this allows the
integration of a business rule engine in the recommendation process inside
the system where I'm working).
Now my problem is that for users with lots of preferences (200+) this
estimation process takes forever (49second+). I'm assuming the issue lies
into the calculation of the similarity measurements; so I though I'll do
this asynchroniously in a train like process, save it, and at start up just
load it into memory this precomputed information. However, I cannot see any
way to load this information into the CachingSimilarity object; nor can I
persist the CachingSimilarity object and load it.
So any ideas, on how to cut down the estimation times?
Thanks,
Bernát GÁBOR
Re: Mahout Similarity Caching
Posted by Gabor Bernat <be...@primeranks.net>.
Thanks Sebastian.
What I fail to see that how can I offer this information to the
recommendation object, once I have calculated it. How can I pass the output
file to the GenericItemBasedRecommender that I use to estimate preferences?
Bernát GÁBOR
On Tue, Apr 23, 2013 at 3:15 PM, Sebastian Schelter <ss...@apache.org> wrote:
> Hi Bernat,
>
> you can do the offline similarity calculation on a single machine with
>
> o.a.m.cf.taste.impl.similarity.precompute.MultithreadedBatchItemSimilarities
>
> or on a Hadoop cluster (if necessary) with
> o.a.m.cf.taste.hadoop.similarity.item.ItemSimilarityJob
>
> I think such a setup is much easier than coming up with a complicated
> caching logic.
>
> Best,
> Sebastian
>
> On 23.04.2013 15:09, Gabor Bernat wrote:
> > Well,
> >
> > assume that we have a live system. The system is serving requests 24/7,
> and
> > in order to update the model periodically we recreate it on another
> machine
> > and just save it (like to a database), and as update just load the saved
> > data model and exchange it with the one running prior. On this another
> > machine the similarities could be calculated also, saved, and on the new
> > machine just load it.
> >
> > The adventage in this is that you can offload similarity calculation to
> an
> > offline system without paying the cold start price on the live/online
> > system. Loading the pre calcualted top used similarities should certainly
> > be less costly than doing all this on the live system, even if
> concurently.
> > The problem with calculating them on the live system is that for the
> first
> > 30-40 minutes you'll have long response times compared to the state when
> > your cache is filled.
> >
> >
> > Bernát GÁBOR
> >
> >
> > On Tue, Apr 23, 2013 at 2:54 PM, Sean Owen <sr...@gmail.com> wrote:
> >
> >> I agree, but how is "pre-adding a cached value for X" different than
> >> "requesting X from the cache"? Either way you get X in the cache.
> >> Computing offline seems the same as computing on-line, but in some
> >> kind of warm-up state or phase. Which can be concurrent with serving
> >> early requests even. You can do everything else you say without a new
> >> operation, like selectively pre-caching certain entries.
> >>
> >> On Tue, Apr 23, 2013 at 1:14 PM, Gabor Bernat <be...@primeranks.net>
> >> wrote:
> >>> CachingSimilarity also allowed to add manually entries, because in that
> >>> case this task could be pushed off to an offline system. And yes, you
> >>> cannot add all the similarities to the caching object, however based on
> >>> history you can select some top (popular) item pairs, and just
> calculate
> >>> for that subset. This could push down the upper request times. Any
> other
> >>> ideas?
> >>>
> >>
> >
>
>
Re: Mahout Similarity Caching
Posted by Sebastian Schelter <ss...@apache.org>.
Hi Bernat,
you can do the offline similarity calculation on a single machine with
o.a.m.cf.taste.impl.similarity.precompute.MultithreadedBatchItemSimilarities
or on a Hadoop cluster (if necessary) with
o.a.m.cf.taste.hadoop.similarity.item.ItemSimilarityJob
I think such a setup is much easier than coming up with a complicated
caching logic.
Best,
Sebastian
On 23.04.2013 15:09, Gabor Bernat wrote:
> Well,
>
> assume that we have a live system. The system is serving requests 24/7, and
> in order to update the model periodically we recreate it on another machine
> and just save it (like to a database), and as update just load the saved
> data model and exchange it with the one running prior. On this another
> machine the similarities could be calculated also, saved, and on the new
> machine just load it.
>
> The adventage in this is that you can offload similarity calculation to an
> offline system without paying the cold start price on the live/online
> system. Loading the pre calcualted top used similarities should certainly
> be less costly than doing all this on the live system, even if concurently.
> The problem with calculating them on the live system is that for the first
> 30-40 minutes you'll have long response times compared to the state when
> your cache is filled.
>
>
> Bernát GÁBOR
>
>
> On Tue, Apr 23, 2013 at 2:54 PM, Sean Owen <sr...@gmail.com> wrote:
>
>> I agree, but how is "pre-adding a cached value for X" different than
>> "requesting X from the cache"? Either way you get X in the cache.
>> Computing offline seems the same as computing on-line, but in some
>> kind of warm-up state or phase. Which can be concurrent with serving
>> early requests even. You can do everything else you say without a new
>> operation, like selectively pre-caching certain entries.
>>
>> On Tue, Apr 23, 2013 at 1:14 PM, Gabor Bernat <be...@primeranks.net>
>> wrote:
>>> CachingSimilarity also allowed to add manually entries, because in that
>>> case this task could be pushed off to an offline system. And yes, you
>>> cannot add all the similarities to the caching object, however based on
>>> history you can select some top (popular) item pairs, and just calculate
>>> for that subset. This could push down the upper request times. Any other
>>> ideas?
>>>
>>
>
Re: Mahout Similarity Caching
Posted by Gabor Bernat <be...@primeranks.net>.
Well,
assume that we have a live system. The system is serving requests 24/7, and
in order to update the model periodically we recreate it on another machine
and just save it (like to a database), and as update just load the saved
data model and exchange it with the one running prior. On this another
machine the similarities could be calculated also, saved, and on the new
machine just load it.
The adventage in this is that you can offload similarity calculation to an
offline system without paying the cold start price on the live/online
system. Loading the pre calcualted top used similarities should certainly
be less costly than doing all this on the live system, even if concurently.
The problem with calculating them on the live system is that for the first
30-40 minutes you'll have long response times compared to the state when
your cache is filled.
Bernát GÁBOR
On Tue, Apr 23, 2013 at 2:54 PM, Sean Owen <sr...@gmail.com> wrote:
> I agree, but how is "pre-adding a cached value for X" different than
> "requesting X from the cache"? Either way you get X in the cache.
> Computing offline seems the same as computing on-line, but in some
> kind of warm-up state or phase. Which can be concurrent with serving
> early requests even. You can do everything else you say without a new
> operation, like selectively pre-caching certain entries.
>
> On Tue, Apr 23, 2013 at 1:14 PM, Gabor Bernat <be...@primeranks.net>
> wrote:
> > CachingSimilarity also allowed to add manually entries, because in that
> > case this task could be pushed off to an offline system. And yes, you
> > cannot add all the similarities to the caching object, however based on
> > history you can select some top (popular) item pairs, and just calculate
> > for that subset. This could push down the upper request times. Any other
> > ideas?
> >
>
Re: Mahout Similarity Caching
Posted by Sean Owen <sr...@gmail.com>.
I agree, but how is "pre-adding a cached value for X" different than
"requesting X from the cache"? Either way you get X in the cache.
Computing offline seems the same as computing on-line, but in some
kind of warm-up state or phase. Which can be concurrent with serving
early requests even. You can do everything else you say without a new
operation, like selectively pre-caching certain entries.
On Tue, Apr 23, 2013 at 1:14 PM, Gabor Bernat <be...@primeranks.net> wrote:
> CachingSimilarity also allowed to add manually entries, because in that
> case this task could be pushed off to an offline system. And yes, you
> cannot add all the similarities to the caching object, however based on
> history you can select some top (popular) item pairs, and just calculate
> for that subset. This could push down the upper request times. Any other
> ideas?
>
Re: Mahout Similarity Caching
Posted by Gabor Bernat <be...@primeranks.net>.
Hello,
So I found out why the extremes. I also needed to make estimations to some
items not present in the data model. To test if an item is inside the model
I used the getPreferences for the item (because there isn't a does model
contains item ID member function for the model), which throws an exception
if the item id is not present inside the model. If the exception was thrown
I just catched and moved on. However, if I had 1-3k of such items the
exception handling summed up to the 49s. Now I created a hash map with the
itemIds, and just check prior to the estimation request if it's there and
now I'ts a lot better: 500-900ms on first call, 100-200ms once the caching
starts to kick in (I've also extended the model to 13k items). The cold
requests are still quite coumbersome. Given that the model is static, I
feel that the need of the cold requests could be mitigated if the
CachingSimilarity also allowed to add manually entries, because in that
case this task could be pushed off to an offline system. And yes, you
cannot add all the similarities to the caching object, however based on
history you can select some top (popular) item pairs, and just calculate
for that subset. This could push down the upper request times. Any other
ideas?
Thanks,
Bernát GÁBOR
On Tue, Apr 23, 2013 at 9:17 AM, Sean Owen <sr...@gmail.com> wrote:
> That still sounds far too high, and it would be interested to profile
> to see exactly what's slow. A recommendation entails making estimates
> for most or all items, and so should be about as fast as making
> estimates directly for a few thousand. Tanimoto similarity is trivial.
> In fact it may be slowing things down to cache it.
>
> You can 'warm up' the cache by requesting similarities, which will
> then be cached. There's no real point in a separate method to give it
> a cached value -- it can figure those out. The problem is, what do you
> cache? you can't cache everything and you don't know what's needed
> ahead of time.
>
> Something else is not right here I think, like, the measurement is
> including some other time.
>
> On Tue, Apr 23, 2013 at 6:20 AM, Gabor Bernat <be...@primeranks.net>
> wrote:
> > Nope, and nope.
> >
> > Note that this is an outlier example, however even in other cases it does
> > takes 500ms+ which is way to much for what I need.
> >
> > Thanks,
> >
> > Bernát GÁBOR
> >
> >
> > On Tue, Apr 23, 2013 at 12:53 AM, Sean Owen <sr...@gmail.com> wrote:
> >
> >> 49 seconds is orders of magnitude too long -- something is very wrong
> >> here, for so little data. Are you running this off a database? or are
> >> you somehow counting the overhead of 3-4K network calls?
> >>
> >> On Mon, Apr 22, 2013 at 11:22 PM, Gabor Bernat <be...@primeranks.net>
> >> wrote:
> >> > Hello,
> >> >
> >> > I'm using Mahout in a system, where the typical response time should
> be
> >> > below 100ms. I'm using an item based recommender with float preference
> >> > values (with Tanimato similarity for now, which is passed into a
> >> > CachingItemSimilarity objec for performance reasonst). My model has
> >> around
> >> > 7k items, 26k users with around 100k preferences linking them.
> >> >
> >> > Instead of performing a recommendation, I only need to estimate
> >> preferences
> >> > of the user for around 3-4k items (this is important, as this allows
> the
> >> > integration of a business rule engine in the recommendation process
> >> inside
> >> > the system where I'm working).
> >> >
> >> > Now my problem is that for users with lots of preferences (200+) this
> >> > estimation process takes forever (49second+). I'm assuming the issue
> lies
> >> > into the calculation of the similarity measurements; so I though I'll
> do
> >> > this asynchroniously in a train like process, save it, and at start up
> >> just
> >> > load it into memory this precomputed information. However, I cannot
> see
> >> any
> >> > way to load this information into the CachingSimilarity object; nor
> can I
> >> > persist the CachingSimilarity object and load it.
> >> >
> >> > So any ideas, on how to cut down the estimation times?
> >> >
> >> > Thanks,
> >> >
> >> > Bernát GÁBOR
> >>
>
Re: Mahout Similarity Caching
Posted by Sean Owen <sr...@gmail.com>.
That still sounds far too high, and it would be interested to profile
to see exactly what's slow. A recommendation entails making estimates
for most or all items, and so should be about as fast as making
estimates directly for a few thousand. Tanimoto similarity is trivial.
In fact it may be slowing things down to cache it.
You can 'warm up' the cache by requesting similarities, which will
then be cached. There's no real point in a separate method to give it
a cached value -- it can figure those out. The problem is, what do you
cache? you can't cache everything and you don't know what's needed
ahead of time.
Something else is not right here I think, like, the measurement is
including some other time.
On Tue, Apr 23, 2013 at 6:20 AM, Gabor Bernat <be...@primeranks.net> wrote:
> Nope, and nope.
>
> Note that this is an outlier example, however even in other cases it does
> takes 500ms+ which is way to much for what I need.
>
> Thanks,
>
> Bernát GÁBOR
>
>
> On Tue, Apr 23, 2013 at 12:53 AM, Sean Owen <sr...@gmail.com> wrote:
>
>> 49 seconds is orders of magnitude too long -- something is very wrong
>> here, for so little data. Are you running this off a database? or are
>> you somehow counting the overhead of 3-4K network calls?
>>
>> On Mon, Apr 22, 2013 at 11:22 PM, Gabor Bernat <be...@primeranks.net>
>> wrote:
>> > Hello,
>> >
>> > I'm using Mahout in a system, where the typical response time should be
>> > below 100ms. I'm using an item based recommender with float preference
>> > values (with Tanimato similarity for now, which is passed into a
>> > CachingItemSimilarity objec for performance reasonst). My model has
>> around
>> > 7k items, 26k users with around 100k preferences linking them.
>> >
>> > Instead of performing a recommendation, I only need to estimate
>> preferences
>> > of the user for around 3-4k items (this is important, as this allows the
>> > integration of a business rule engine in the recommendation process
>> inside
>> > the system where I'm working).
>> >
>> > Now my problem is that for users with lots of preferences (200+) this
>> > estimation process takes forever (49second+). I'm assuming the issue lies
>> > into the calculation of the similarity measurements; so I though I'll do
>> > this asynchroniously in a train like process, save it, and at start up
>> just
>> > load it into memory this precomputed information. However, I cannot see
>> any
>> > way to load this information into the CachingSimilarity object; nor can I
>> > persist the CachingSimilarity object and load it.
>> >
>> > So any ideas, on how to cut down the estimation times?
>> >
>> > Thanks,
>> >
>> > Bernát GÁBOR
>>
Re: Mahout Similarity Caching
Posted by Gabor Bernat <be...@primeranks.net>.
Nope, and nope.
Note that this is an outlier example, however even in other cases it does
takes 500ms+ which is way to much for what I need.
Thanks,
Bernát GÁBOR
On Tue, Apr 23, 2013 at 12:53 AM, Sean Owen <sr...@gmail.com> wrote:
> 49 seconds is orders of magnitude too long -- something is very wrong
> here, for so little data. Are you running this off a database? or are
> you somehow counting the overhead of 3-4K network calls?
>
> On Mon, Apr 22, 2013 at 11:22 PM, Gabor Bernat <be...@primeranks.net>
> wrote:
> > Hello,
> >
> > I'm using Mahout in a system, where the typical response time should be
> > below 100ms. I'm using an item based recommender with float preference
> > values (with Tanimato similarity for now, which is passed into a
> > CachingItemSimilarity objec for performance reasonst). My model has
> around
> > 7k items, 26k users with around 100k preferences linking them.
> >
> > Instead of performing a recommendation, I only need to estimate
> preferences
> > of the user for around 3-4k items (this is important, as this allows the
> > integration of a business rule engine in the recommendation process
> inside
> > the system where I'm working).
> >
> > Now my problem is that for users with lots of preferences (200+) this
> > estimation process takes forever (49second+). I'm assuming the issue lies
> > into the calculation of the similarity measurements; so I though I'll do
> > this asynchroniously in a train like process, save it, and at start up
> just
> > load it into memory this precomputed information. However, I cannot see
> any
> > way to load this information into the CachingSimilarity object; nor can I
> > persist the CachingSimilarity object and load it.
> >
> > So any ideas, on how to cut down the estimation times?
> >
> > Thanks,
> >
> > Bernát GÁBOR
>
Re: Mahout Similarity Caching
Posted by Sean Owen <sr...@gmail.com>.
49 seconds is orders of magnitude too long -- something is very wrong
here, for so little data. Are you running this off a database? or are
you somehow counting the overhead of 3-4K network calls?
On Mon, Apr 22, 2013 at 11:22 PM, Gabor Bernat <be...@primeranks.net> wrote:
> Hello,
>
> I'm using Mahout in a system, where the typical response time should be
> below 100ms. I'm using an item based recommender with float preference
> values (with Tanimato similarity for now, which is passed into a
> CachingItemSimilarity objec for performance reasonst). My model has around
> 7k items, 26k users with around 100k preferences linking them.
>
> Instead of performing a recommendation, I only need to estimate preferences
> of the user for around 3-4k items (this is important, as this allows the
> integration of a business rule engine in the recommendation process inside
> the system where I'm working).
>
> Now my problem is that for users with lots of preferences (200+) this
> estimation process takes forever (49second+). I'm assuming the issue lies
> into the calculation of the similarity measurements; so I though I'll do
> this asynchroniously in a train like process, save it, and at start up just
> load it into memory this precomputed information. However, I cannot see any
> way to load this information into the CachingSimilarity object; nor can I
> persist the CachingSimilarity object and load it.
>
> So any ideas, on how to cut down the estimation times?
>
> Thanks,
>
> Bernát GÁBOR