You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Hans Pikkemaat <h....@tsi-solutions.nl> on 2009/11/11 14:43:51 UTC

Object Caching

Hi,

I use the latest version of cayenne, 3.0b and am experimenting with the 
object caching features.

The documentation states that committed objects are purged from the 
cache because it uses weak references.
(http://cayenne.apache.org/doc/individual-object-caching.html)

If I however run a query using SQLTemplate which caches the objects into 
the dataContext local cache (objectstore),
the objects don't seem to be purged at all. If I simply run the query 
dump the contents using an iterator on the resulting
List then the nr of registered objects in the objectstore stays the same 
(dataContext.getObjectStore().registeredObjectsCount()).
Even if I manually run System.gc() I don't see any changes (I know this 
can be normal as gc() doesn't guarantee anything)

What am I doing wrong? Under which circumstances will cayenne purge the 
cache?

tx

Hans

Re: Object Caching

Posted by Michael Gentry <mg...@masslight.net>.
Hi Hans,

Even using a paginated query in Cayenne, it would've eventually pulled
everything into memory.  The paginated query is really designed to be
used in a UI where the user is going to see a limited amount of data
and probably not page too many times.  The iterated query is the best
approach for trying to process a large number of records in Cayenne.

Good luck!

mrg

On Fri, Nov 13, 2009 at 10:49 AM, Hans Pikkemaat
<h....@tsi-solutions.nl> wrote:
> Hi,
>
> Of course I don't want to load the whole thing into memory.
> I want to run the query and use an iterator to go through the results.
> Using paging the jdbc driver is able to produce chunks which prevents
> the whole resultset to be loaded into memory.
>
> This same principle I was trying to accomplish using cayenne but clearly
> without success.
>
> So I'm going to fall back to cayenne iterated query or even jdbc.
>
> tx
>
> Hans
>
>
> Michael Gentry wrote:
>>
>> I'm not exactly sure what you are trying to accomplish, but could you
>> use plain SQL to do the job (run it from an SQL prompt)?  That's the
>> approach I normally take when I have to do updates to large amounts of
>> data.  Especially for a one-off task or something ill-suited to Java
>> code.  Even if you were using raw JDBC (no ORM) and tried to pull back
>> 2.5 million records it would be difficult.  I don't know the size of
>> the data record you are using, but if it is even 1k (not an
>> unreasonable size) it would require 2.5 GB of RAM just to hold the
>> records.
>>
>> mrg
>>
>>
>> On Fri, Nov 13, 2009 at 10:20 AM, Hans Pikkemaat
>> <h....@tsi-solutions.nl> wrote:
>>
>>>
>>> Hi,
>>>
>>> That was the initial approax I tried. The problem with this is that I
>>> cannot
>>> manually
>>> create relations between objects constructed from data rows. This means
>>> that
>>> when
>>> I access the detail table through the relation it will execute a query to
>>> get them from
>>> the database.
>>>
>>> If I have 100 main records it runs 100 queries to get all the details.
>>> This is not performing well. I need to run 1 query which is doing a left
>>> join and
>>> gets all the data in one go.
>>>
>>> But I totally agree with you that ORM is too much overhead. I don't need
>>> caching
>>> or something like that. Actually I'm trying to prevent that it is caching
>>> the records.
>>> I'm working on a solution now that is using the iterated query which is
>>> returning
>>> datarows where I construct new objects and the relationsship between them
>>> myself.
>>>
>>> tx
>>>
>>> Hans
>>>
>>>
>>> Michael Gentry wrote:
>>>
>>>>
>>>> Not just Cayenne, Hans.  No ORM efficiently handles the scale you are
>>>> talking about.  You need to find a way to break your query down into
>>>> smaller chunks to process.  What you are doing might be workable with
>>>> 50k records, but not 2.5m.  Find a way to break your query down into
>>>> smaller units to process or explore what Andrus suggested with
>>>> ResultIterator:
>>>>
>>>> http://cayenne.apache.org/doc/iterating-through-data-rows.html
>>>>
>>>> If you can loop over one record at a time and process it (thereby
>>>> letting the garbage collector clean out the ones you have processed)
>>>> then your memory usage should be somewhat stable and manageable, even
>>>> if the initial query time takes a while.
>>>>
>>>> mrg
>>>>
>>>>
>>>> On Fri, Nov 13, 2009 at 7:09 AM, Hans Pikkemaat
>>>> <h....@tsi-solutions.nl> wrote:
>>>>
>>>>
>>>>>
>>>>> Anyway, my conclusion is indeed: don't use cayenne for large query
>>>>> processing.
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
>

Re: Object Caching

Posted by Hans Pikkemaat <h....@tsi-solutions.nl>.
Hi,

Of course I don't want to load the whole thing into memory.
I want to run the query and use an iterator to go through the results.
Using paging the jdbc driver is able to produce chunks which prevents
the whole resultset to be loaded into memory.

This same principle I was trying to accomplish using cayenne but clearly
without success.

So I'm going to fall back to cayenne iterated query or even jdbc.

tx

Hans


Michael Gentry wrote:
> I'm not exactly sure what you are trying to accomplish, but could you
> use plain SQL to do the job (run it from an SQL prompt)?  That's the
> approach I normally take when I have to do updates to large amounts of
> data.  Especially for a one-off task or something ill-suited to Java
> code.  Even if you were using raw JDBC (no ORM) and tried to pull back
> 2.5 million records it would be difficult.  I don't know the size of
> the data record you are using, but if it is even 1k (not an
> unreasonable size) it would require 2.5 GB of RAM just to hold the
> records.
>
> mrg
>
>
> On Fri, Nov 13, 2009 at 10:20 AM, Hans Pikkemaat
> <h....@tsi-solutions.nl> wrote:
>   
>> Hi,
>>
>> That was the initial approax I tried. The problem with this is that I cannot
>> manually
>> create relations between objects constructed from data rows. This means that
>> when
>> I access the detail table through the relation it will execute a query to
>> get them from
>> the database.
>>
>> If I have 100 main records it runs 100 queries to get all the details.
>> This is not performing well. I need to run 1 query which is doing a left
>> join and
>> gets all the data in one go.
>>
>> But I totally agree with you that ORM is too much overhead. I don't need
>> caching
>> or something like that. Actually I'm trying to prevent that it is caching
>> the records.
>> I'm working on a solution now that is using the iterated query which is
>> returning
>> datarows where I construct new objects and the relationsship between them
>> myself.
>>
>> tx
>>
>> Hans
>>
>>
>> Michael Gentry wrote:
>>     
>>> Not just Cayenne, Hans.  No ORM efficiently handles the scale you are
>>> talking about.  You need to find a way to break your query down into
>>> smaller chunks to process.  What you are doing might be workable with
>>> 50k records, but not 2.5m.  Find a way to break your query down into
>>> smaller units to process or explore what Andrus suggested with
>>> ResultIterator:
>>>
>>> http://cayenne.apache.org/doc/iterating-through-data-rows.html
>>>
>>> If you can loop over one record at a time and process it (thereby
>>> letting the garbage collector clean out the ones you have processed)
>>> then your memory usage should be somewhat stable and manageable, even
>>> if the initial query time takes a while.
>>>
>>> mrg
>>>
>>>
>>> On Fri, Nov 13, 2009 at 7:09 AM, Hans Pikkemaat
>>> <h....@tsi-solutions.nl> wrote:
>>>
>>>       
>>>> Anyway, my conclusion is indeed: don't use cayenne for large query
>>>> processing.
>>>>
>>>>         
>>>       
>>
>>     
>
>   



Re: Object Caching

Posted by Michael Gentry <mg...@masslight.net>.
I'm not exactly sure what you are trying to accomplish, but could you
use plain SQL to do the job (run it from an SQL prompt)?  That's the
approach I normally take when I have to do updates to large amounts of
data.  Especially for a one-off task or something ill-suited to Java
code.  Even if you were using raw JDBC (no ORM) and tried to pull back
2.5 million records it would be difficult.  I don't know the size of
the data record you are using, but if it is even 1k (not an
unreasonable size) it would require 2.5 GB of RAM just to hold the
records.

mrg


On Fri, Nov 13, 2009 at 10:20 AM, Hans Pikkemaat
<h....@tsi-solutions.nl> wrote:
> Hi,
>
> That was the initial approax I tried. The problem with this is that I cannot
> manually
> create relations between objects constructed from data rows. This means that
> when
> I access the detail table through the relation it will execute a query to
> get them from
> the database.
>
> If I have 100 main records it runs 100 queries to get all the details.
> This is not performing well. I need to run 1 query which is doing a left
> join and
> gets all the data in one go.
>
> But I totally agree with you that ORM is too much overhead. I don't need
> caching
> or something like that. Actually I'm trying to prevent that it is caching
> the records.
> I'm working on a solution now that is using the iterated query which is
> returning
> datarows where I construct new objects and the relationsship between them
> myself.
>
> tx
>
> Hans
>
>
> Michael Gentry wrote:
>>
>> Not just Cayenne, Hans.  No ORM efficiently handles the scale you are
>> talking about.  You need to find a way to break your query down into
>> smaller chunks to process.  What you are doing might be workable with
>> 50k records, but not 2.5m.  Find a way to break your query down into
>> smaller units to process or explore what Andrus suggested with
>> ResultIterator:
>>
>> http://cayenne.apache.org/doc/iterating-through-data-rows.html
>>
>> If you can loop over one record at a time and process it (thereby
>> letting the garbage collector clean out the ones you have processed)
>> then your memory usage should be somewhat stable and manageable, even
>> if the initial query time takes a while.
>>
>> mrg
>>
>>
>> On Fri, Nov 13, 2009 at 7:09 AM, Hans Pikkemaat
>> <h....@tsi-solutions.nl> wrote:
>>
>>>
>>> Anyway, my conclusion is indeed: don't use cayenne for large query
>>> processing.
>>>
>>
>>
>
>
>

Re: Object Caching

Posted by Hans Pikkemaat <h....@tsi-solutions.nl>.
Hi,

That was the initial approax I tried. The problem with this is that I 
cannot manually
create relations between objects constructed from data rows. This means 
that when
I access the detail table through the relation it will execute a query 
to get them from
the database.

If I have 100 main records it runs 100 queries to get all the details.
This is not performing well. I need to run 1 query which is doing a left 
join and
gets all the data in one go.

But I totally agree with you that ORM is too much overhead. I don't need 
caching
or something like that. Actually I'm trying to prevent that it is 
caching the records.
I'm working on a solution now that is using the iterated query which is 
returning
datarows where I construct new objects and the relationsship between 
them myself.

tx

Hans


Michael Gentry wrote:
> Not just Cayenne, Hans.  No ORM efficiently handles the scale you are
> talking about.  You need to find a way to break your query down into
> smaller chunks to process.  What you are doing might be workable with
> 50k records, but not 2.5m.  Find a way to break your query down into
> smaller units to process or explore what Andrus suggested with
> ResultIterator:
>
> http://cayenne.apache.org/doc/iterating-through-data-rows.html
>
> If you can loop over one record at a time and process it (thereby
> letting the garbage collector clean out the ones you have processed)
> then your memory usage should be somewhat stable and manageable, even
> if the initial query time takes a while.
>
> mrg
>
>
> On Fri, Nov 13, 2009 at 7:09 AM, Hans Pikkemaat
> <h....@tsi-solutions.nl> wrote:
>   
>> Anyway, my conclusion is indeed: don't use cayenne for large query
>> processing.
>>     
>
>   



Re: Object Caching

Posted by Michael Gentry <mg...@masslight.net>.
Not just Cayenne, Hans.  No ORM efficiently handles the scale you are
talking about.  You need to find a way to break your query down into
smaller chunks to process.  What you are doing might be workable with
50k records, but not 2.5m.  Find a way to break your query down into
smaller units to process or explore what Andrus suggested with
ResultIterator:

http://cayenne.apache.org/doc/iterating-through-data-rows.html

If you can loop over one record at a time and process it (thereby
letting the garbage collector clean out the ones you have processed)
then your memory usage should be somewhat stable and manageable, even
if the initial query time takes a while.

mrg


On Fri, Nov 13, 2009 at 7:09 AM, Hans Pikkemaat
<h....@tsi-solutions.nl> wrote:
> Anyway, my conclusion is indeed: don't use cayenne for large query
> processing.

Re: Object Caching

Posted by Hans Pikkemaat <h....@tsi-solutions.nl>.
Hi,

No not completely. Because of the problems I was having with paging in 
combination with SQLTemplate and prefetching
I was doing a simple test to see how much memory would actually be 
required to run a big query.
This in an attempt to calculate the total memory I would need for my 2.5 
mil query.

This test does not use paging (because of the earlier problems) but did 
use prefetching (because I don't
want to run 2.5 million queries for the detail table).

The problem I saw is the following. The initial query which accesses the 
main table and does a left join
to the detail table took about 1 minute. Then it took cayenne 2 minutes 
to construct the objects and
related objects from the datarows produced from this query. This 
construction does the job
correctly but in my opinion it is taking too long. If the main query can 
run in 1 minute and get all
the data from the database (which is IO and normally would be seen as 
the bottleneck) why
does it take 2 minutes to convert this into objects and relations.

The conversion into memory goes fairly quickly. After that I only see 
100% cpu and no changes
in memory occupation (used profiler). From stack traces I can see that 
all the time spent is in

    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction()

and

    
org.apache.cayenne.access.DataDomainQueryAction.interceptObjectConversion()

which finally calls

    org.apache.cayenne.query.PrefetchTreeNode.traverse(PrefetchProcessor)

which does all the time consuming work.

I think there is a piece of code somewhere which traverses a list of 
some kind
which is inefficient. Maybe a HashMap is used with a key object without
hashCode/equals methods?

Answering your points:

1) As I'm not using paging here prefetching does help because I don't 
have to query the detail table separately.
2) Yes I do need these 2.5 million records because after some 
investigation I will forward records I need.
    No its clearly not a user interface. I totally agree that Cayenne at 
least is not the best way to use.

What I initially started to use is the iterated query such I could 
iterate over the data rows and construct the
objects on the fly which would then be forwarded.

The problem here is that I cannot use prefetching nor can I manually 
construct relationships. The code is
probably there (prefetching uses it) but the api does not give me a (n 
easy way to) handle to use it.
This effectively leaves me running separate queries for each main record 
what is not performing.

Anyway, my conclusion is indeed: don't use cayenne for large query 
processing.

tx

Hans





Aristedes Maniatis wrote:
> On 13/11/09 10:04 PM, Hans Pikkemaat wrote:
>   
>> I ran some tests using 3.0b with SQLTemplate in combination with
>> prefetching and found
>> a possible new problem.
>>
>> It seems that when running the query in eg 1 minute, it takes about 2
>> minutes before cayenne
>> has constructed the prefetched objects.
>>
>> My query produces 2.5 million records. The query will take about 30
>> minutes. Construction
>> of the objects will then take an extra hour.
>>     
>
>
> Just to be clear about what you are doing:
>
> * Cayenne 3.0 beta 1
> * SQL template query
> * prefeching across to-many join
> * paging on
>
> You expect the first query (which gets hollow objects) to NOT include the prefetch JOIN, but when fetching a page of results, it should use the prefetch. Cayenne is constructing the first query which includes the JOIN and that makes it take 30 minutes in your database to return 2.5 million records.
>
> Is that correct?
>
>
> My opinions:
>
> 1. Does prefetch really help here anyway? You are only getting (say) 100 records at a time, so the extra queries to follow the relations may not be that significant.
>
> 2. Do you really want to fetch 2.5 million rows? If so, I assume this is not a user interface :-)  Perhaps Cayenne (or any ORM for that matter) is not the best way to batch process that many rows.
>
>
>
> Ari
>
>   


Re: Object Caching

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Nov 13, 2009, at 1:44 PM, Aristedes Maniatis wrote:

> 2. Do you really want to fetch 2.5 million rows? If so, I assume  
> this is not a user interface :-)  Perhaps Cayenne (or any ORM for  
> that matter) is not the best way to batch process that many rows.

Yeah, I was wondering the same thing, but didn't want to second guess  
too much. The discussion was still useful, as I we may fix some of the  
issues discussed here (such as single-row prefetch resolving), but  
there is an ORM overhead, and that's unavoidable.

Cayenne can still be helpful to get the data out, but using  
ResultIterator/DataRows is probably the way to go.

Andrus



Re: Object Caching

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 13/11/09 10:04 PM, Hans Pikkemaat wrote:
> I ran some tests using 3.0b with SQLTemplate in combination with
> prefetching and found
> a possible new problem.
>
> It seems that when running the query in eg 1 minute, it takes about 2
> minutes before cayenne
> has constructed the prefetched objects.
>
> My query produces 2.5 million records. The query will take about 30
> minutes. Construction
> of the objects will then take an extra hour.


Just to be clear about what you are doing:

* Cayenne 3.0 beta 1
* SQL template query
* prefeching across to-many join
* paging on

You expect the first query (which gets hollow objects) to NOT include the prefetch JOIN, but when fetching a page of results, it should use the prefetch. Cayenne is constructing the first query which includes the JOIN and that makes it take 30 minutes in your database to return 2.5 million records.

Is that correct?


My opinions:

1. Does prefetch really help here anyway? You are only getting (say) 100 records at a time, so the extra queries to follow the relations may not be that significant.

2. Do you really want to fetch 2.5 million rows? If so, I assume this is not a user interface :-)  Perhaps Cayenne (or any ORM for that matter) is not the best way to batch process that many rows.



Ari

-- 

-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Re: Object Caching

Posted by Hans Pikkemaat <h....@tsi-solutions.nl>.
Hi,

I ran some tests using 3.0b with SQLTemplate in combination with 
prefetching and found
a possible new problem.

It seems that when running the query in eg 1 minute, it takes about 2 
minutes before cayenne
has constructed the prefetched objects.

My query produces 2.5 million records. The query will take about 30 
minutes. Construction
of the objects will then take an extra hour.

This is not really workable.

Hans

Hans Pikkemaat wrote:
> Hi,
>
> What I can see when I use paging in combination with SQLTemplate is this:
>
> Cayenne first runs the main SQLTemplate query which is stored in memory
>  
> When I get the first page it determines the key values of the main 
> query which it then
> uses in a new query which will return the main table plus the detail 
> table data.
> This will produce the main table object through which the detail table 
> is accessible.
>
> The problem here is that the key of the main table is used only. The 
> SQLTemplate query was manually
> constructed and does a query on the main table and a left join to the 
> detail table so this will produce
> a duplicate key value where a main table record has 2 related detail 
> table records.
>
> This doesnt have to be a problem, actually the query does return the 
> number of records used as page
> size. But internally in cayenne something weird happens. Somehow the 
> duplicate records are remove
> and the IncrementalFaultList.checkPageResultConsistency method throws 
> an exception for this.
>
> Because the main query returns the main object but also the detail 
> object I find it strange
> that the query generated for the page only uses the main table key. I 
> would expect that
> it also would use the key of the detail table.
>
> An example. Say I have a main table key 1 and related detail records 
> with key 1, 2 and 3.
> Say I run the SQLTemplate which returns key 1 but only key 1 and 2 for 
> the detail table.
>
> The page query will now run for all detail records and return all 
> records which I did not
> request.
>
> From this I'm concluding that if an SQLTemplate is used it is not 
> usefull (read: faulty) to
> include the detail table in this query. When paging is used all the 
> detail tables are automatically
> queried.
>
> If I write the main SQLTemplate query such it only returns the main 
> object then the
> Exception does not occur.
>
> My conclusion is then that if you want to use paging with SQLTemplate 
> the main
> query should only return the main table. Prefetching will then return 
> ALL related
> table records.
>
> tx
>
> HPI
>
> Andrus Adamchik wrote:
>> Yeah, still need to check that one.
>>
>> On Nov 12, 2009, at 10:43 AM, Hans Pikkemaat wrote:
>>
>>   
>>> Hi,
>>>
>>> Yes, the paginated query would indeed be the only way for me to go  
>>> forward.
>>> The problem however is that I get the exception I posted earlier.
>>>
>>> tx
>>>
>>> Hans
>>>
>>> Andrus Adamchik wrote:
>>>     
>>>> For paginated queries we contemplated a strategy of a list with   
>>>> constant size of fully resolved objects. I.e. when a page is  
>>>> swapped  in, some other (LRU?) page is swapped out. We decided  
>>>> against it, as  in a general case it is hard to consistently  
>>>> predict which page should  be swapped out.
>>>>
>>>> However it should be rather easy to write such a list for a  
>>>> specific  case with a known access order (e.g. a standard iteration  
>>>> order). In  fact I would vote to even include such implementation  
>>>> in Cayenne going  forward.
>>>>
>>>> More specifically, you can extend IncrementalFaultList [1],  
>>>> overriding  'resolveInterval' to swap out previously read pages,  
>>>> turning them back  into ids. And the good part is that you can use  
>>>> your extension  directly without any need to modify the rest of  
>>>> Cayenne.
>>>>
>>>> Andrus
>>>>
>>>>
>>>> [1] http://cayenne.apache.org/doc/api/org/apache/cayenne/access/IncrementalFaultList.html
>>>>
>>>>
>>>> On Nov 12, 2009, at 10:07 AM, Hans Pikkemaat wrote:
>>>>
>>>>       
>>>>> Hi,
>>>>>
>>>>> So this means that if I use a generic query that the query  
>>>>> results  are always stored
>>>>> completely in the object store (or the query cache if I configure  
>>>>> it).
>>>>>
>>>>> Objects are returned in a list so as long I have a reference to  
>>>>> this  list (because I'm
>>>>> traversing it) these objects are not garbage collected.
>>>>>
>>>>> If I use the query cache the full query results are cached. This   
>>>>> means that I can only
>>>>> tell it to remove the whole query.
>>>>>
>>>>> Effectively this means I'm unable to run a big query and process  
>>>>> the  results as a stream.
>>>>> So I cannot process the first results and then somehow make them   
>>>>> available for
>>>>> garbage collection.
>>>>>
>>>>> The only option I have would be the iterated query but this is  
>>>>> only  usefull for queries
>>>>> one 1 table without any relations because it is not possible to  
>>>>> use  prefetching nor is
>>>>> it possible to manually construct relations between obects.
>>>>>
>>>>> My conclusion here is that cayenne is simply not suitable for  
>>>>> doing  large batch wise
>>>>> query processing because of the memory implications.
>>>>>
>>>>> tx
>>>>>
>>>>> HPI
>>>>>
>>>>> Andrus Adamchik wrote:
>>>>>
>>>>>         
>>>>>> As mentioned in the docs, individual objects and query lists are
>>>>>> cached independently. Of course query lists contain a subset of   
>>>>>> cached
>>>>>> object store objects inside the lists. An object won't get gc'd  
>>>>>> if it
>>>>>> is also stored in the query list.
>>>>>>
>>>>>> Now list cache expiration is controlled via query cache factory. By
>>>>>> default this is an LRU map, so as long as the map has enough  
>>>>>> space to
>>>>>> hold lists (its capacity == # of lists, not # of objects), the   
>>>>>> objects
>>>>>> won't get gc'd.
>>>>>>
>>>>>> You can explicitly remove entries from the cache via QueryCache   
>>>>>> remove
>>>>>> and removeGroup methods. Or you can use a different  
>>>>>> QueryCacheFactory
>>>>>> that implements some custom expiration/cleanup mechanism.
>>>>>>
>>>>>> Andrus
>>>>>>
>>>>>> On Nov 11, 2009, at 3:43 PM, Hans Pikkemaat wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>           
>>>>>>> Hi,
>>>>>>>
>>>>>>> I use the latest version of cayenne, 3.0b and am experimenting  
>>>>>>> with
>>>>>>> the object caching features.
>>>>>>>
>>>>>>> The documentation states that committed objects are purged from  
>>>>>>> the
>>>>>>> cache because it uses weak references.
>>>>>>> (http://cayenne.apache.org/doc/individual-object-caching.html)
>>>>>>>
>>>>>>> If I however run a query using SQLTemplate which caches the  
>>>>>>> objects
>>>>>>> into the dataContext local cache (objectstore),
>>>>>>> the objects don't seem to be purged at all. If I simply run the
>>>>>>> query dump the contents using an iterator on the resulting
>>>>>>> List then the nr of registered objects in the objectstore stays  
>>>>>>> the
>>>>>>> same (dataContext.getObjectStore().registeredObjectsCount()).
>>>>>>> Even if I manually run System.gc() I don't see any changes (I know
>>>>>>> this can be normal as gc() doesn't guarantee anything)
>>>>>>>
>>>>>>> What am I doing wrong? Under which circumstances will cayenne  
>>>>>>> purge
>>>>>>> the cache?
>>>>>>>
>>>>>>> tx
>>>>>>>
>>>>>>> Hans
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>             
>>>     
>>
>>   
>
> -- 
> 	TSi Solutions
> Neptunusstraat 25
> 7521 WC Enschede
>
> Tel. +31 (0)88 - 25 00 000
> Fax. +31 (0)88 - 25 00 122
> Hans Pikkemaat
> Java Developer (Services Team)
> 	E-mail: h.pikkemaat@tsi-solutions.nl 
> <ma...@tsi-solutions.nl>
>   	www.tsi-solutions.nl <http://www.tsi-solutions.nl/>
> www.toeristiek.nl <http://www.toeristiek.nl/>
> 	
>
> 10 jaar TSi Solutions
> ... marktleider in het automatiseren en outsourcen van werkprocessen 
> in de reisbranche
> ... toonaangevende partij voor het verzamelen, structureren en 
> beschikbaarstellen van reiscontent
> ... Reisrevue Innovatieveer 2008 - Veervolle vermelding
> ... Winnaar Reisrevue Innovatieveer 2009
> ... Top 20 positie in 2008 Deloitte Technology Fast50 Nederland
> ... Top 10 positie in 2009 Deloitte Technology Fast50 Benelux
> ... genomineerd voor Technology 500 EMEA 2009
> TSi Solutions is de handelsnaam van Travel Service International 
> b.v.[KvK 06091935]
> DISCLAIMER: De informatie opgenomen in dit bericht kan vertrouwelijk 
> zijn en is uitsluitend bestemd voor de geadresseerde.
> Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud 
> niet te gebruiken en de afzender direct te informeren door het bericht 
> te retourneren.
> The information contained in this message may be confidential and is 
> intended to be exclusively for the addressee.
> Should you receive this message unintentionally, please do not use the 
> contents herein and notify the sender immediately by return e-mail.



Re: Object Caching

Posted by Hans Pikkemaat <h....@tsi-solutions.nl>.
Hi,

What I can see when I use paging in combination with SQLTemplate is this:

Cayenne first runs the main SQLTemplate query which is stored in memory
 
When I get the first page it determines the key values of the main query 
which it then
uses in a new query which will return the main table plus the detail 
table data.
This will produce the main table object through which the detail table 
is accessible.

The problem here is that the key of the main table is used only. The 
SQLTemplate query was manually
constructed and does a query on the main table and a left join to the 
detail table so this will produce
a duplicate key value where a main table record has 2 related detail 
table records.

This doesnt have to be a problem, actually the query does return the 
number of records used as page
size. But internally in cayenne something weird happens. Somehow the 
duplicate records are remove
and the IncrementalFaultList.checkPageResultConsistency method throws an 
exception for this.

Because the main query returns the main object but also the detail 
object I find it strange
that the query generated for the page only uses the main table key. I 
would expect that
it also would use the key of the detail table.

An example. Say I have a main table key 1 and related detail records 
with key 1, 2 and 3.
Say I run the SQLTemplate which returns key 1 but only key 1 and 2 for 
the detail table.

The page query will now run for all detail records and return all 
records which I did not
request.

 From this I'm concluding that if an SQLTemplate is used it is not 
usefull (read: faulty) to
include the detail table in this query. When paging is used all the 
detail tables are automatically
queried.

If I write the main SQLTemplate query such it only returns the main 
object then the
Exception does not occur.

My conclusion is then that if you want to use paging with SQLTemplate 
the main
query should only return the main table. Prefetching will then return 
ALL related
table records.

tx

HPI

Andrus Adamchik wrote:
> Yeah, still need to check that one.
>
> On Nov 12, 2009, at 10:43 AM, Hans Pikkemaat wrote:
>
>   
>> Hi,
>>
>> Yes, the paginated query would indeed be the only way for me to go  
>> forward.
>> The problem however is that I get the exception I posted earlier.
>>
>> tx
>>
>> Hans
>>
>> Andrus Adamchik wrote:
>>     
>>> For paginated queries we contemplated a strategy of a list with   
>>> constant size of fully resolved objects. I.e. when a page is  
>>> swapped  in, some other (LRU?) page is swapped out. We decided  
>>> against it, as  in a general case it is hard to consistently  
>>> predict which page should  be swapped out.
>>>
>>> However it should be rather easy to write such a list for a  
>>> specific  case with a known access order (e.g. a standard iteration  
>>> order). In  fact I would vote to even include such implementation  
>>> in Cayenne going  forward.
>>>
>>> More specifically, you can extend IncrementalFaultList [1],  
>>> overriding  'resolveInterval' to swap out previously read pages,  
>>> turning them back  into ids. And the good part is that you can use  
>>> your extension  directly without any need to modify the rest of  
>>> Cayenne.
>>>
>>> Andrus
>>>
>>>
>>> [1] http://cayenne.apache.org/doc/api/org/apache/cayenne/access/IncrementalFaultList.html
>>>
>>>
>>> On Nov 12, 2009, at 10:07 AM, Hans Pikkemaat wrote:
>>>
>>>       
>>>> Hi,
>>>>
>>>> So this means that if I use a generic query that the query  
>>>> results  are always stored
>>>> completely in the object store (or the query cache if I configure  
>>>> it).
>>>>
>>>> Objects are returned in a list so as long I have a reference to  
>>>> this  list (because I'm
>>>> traversing it) these objects are not garbage collected.
>>>>
>>>> If I use the query cache the full query results are cached. This   
>>>> means that I can only
>>>> tell it to remove the whole query.
>>>>
>>>> Effectively this means I'm unable to run a big query and process  
>>>> the  results as a stream.
>>>> So I cannot process the first results and then somehow make them   
>>>> available for
>>>> garbage collection.
>>>>
>>>> The only option I have would be the iterated query but this is  
>>>> only  usefull for queries
>>>> one 1 table without any relations because it is not possible to  
>>>> use  prefetching nor is
>>>> it possible to manually construct relations between obects.
>>>>
>>>> My conclusion here is that cayenne is simply not suitable for  
>>>> doing  large batch wise
>>>> query processing because of the memory implications.
>>>>
>>>> tx
>>>>
>>>> HPI
>>>>
>>>> Andrus Adamchik wrote:
>>>>
>>>>         
>>>>> As mentioned in the docs, individual objects and query lists are
>>>>> cached independently. Of course query lists contain a subset of   
>>>>> cached
>>>>> object store objects inside the lists. An object won't get gc'd  
>>>>> if it
>>>>> is also stored in the query list.
>>>>>
>>>>> Now list cache expiration is controlled via query cache factory. By
>>>>> default this is an LRU map, so as long as the map has enough  
>>>>> space to
>>>>> hold lists (its capacity == # of lists, not # of objects), the   
>>>>> objects
>>>>> won't get gc'd.
>>>>>
>>>>> You can explicitly remove entries from the cache via QueryCache   
>>>>> remove
>>>>> and removeGroup methods. Or you can use a different  
>>>>> QueryCacheFactory
>>>>> that implements some custom expiration/cleanup mechanism.
>>>>>
>>>>> Andrus
>>>>>
>>>>> On Nov 11, 2009, at 3:43 PM, Hans Pikkemaat wrote:
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>>> Hi,
>>>>>>
>>>>>> I use the latest version of cayenne, 3.0b and am experimenting  
>>>>>> with
>>>>>> the object caching features.
>>>>>>
>>>>>> The documentation states that committed objects are purged from  
>>>>>> the
>>>>>> cache because it uses weak references.
>>>>>> (http://cayenne.apache.org/doc/individual-object-caching.html)
>>>>>>
>>>>>> If I however run a query using SQLTemplate which caches the  
>>>>>> objects
>>>>>> into the dataContext local cache (objectstore),
>>>>>> the objects don't seem to be purged at all. If I simply run the
>>>>>> query dump the contents using an iterator on the resulting
>>>>>> List then the nr of registered objects in the objectstore stays  
>>>>>> the
>>>>>> same (dataContext.getObjectStore().registeredObjectsCount()).
>>>>>> Even if I manually run System.gc() I don't see any changes (I know
>>>>>> this can be normal as gc() doesn't guarantee anything)
>>>>>>
>>>>>> What am I doing wrong? Under which circumstances will cayenne  
>>>>>> purge
>>>>>> the cache?
>>>>>>
>>>>>> tx
>>>>>>
>>>>>> Hans
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>
>>     
>
>   

-- 
	TSi Solutions
Neptunusstraat 25
7521 WC Enschede

Tel. +31 (0)88 - 25 00 000
Fax. +31 (0)88 - 25 00 122
Hans Pikkemaat
Java Developer (Services Team)
	E-mail: h.pikkemaat@tsi-solutions.nl <ma...@tsi-solutions.nl>
  	www.tsi-solutions.nl <http://www.tsi-solutions.nl/>
www.toeristiek.nl <http://www.toeristiek.nl/>
	

10 jaar TSi Solutions
... marktleider in het automatiseren en outsourcen van werkprocessen in 
de reisbranche
... toonaangevende partij voor het verzamelen, structureren en 
beschikbaarstellen van reiscontent
... Reisrevue Innovatieveer 2008 - Veervolle vermelding
... Winnaar Reisrevue Innovatieveer 2009
... Top 20 positie in 2008 Deloitte Technology Fast50 Nederland
... Top 10 positie in 2009 Deloitte Technology Fast50 Benelux
... genomineerd voor Technology 500 EMEA 2009
TSi Solutions is de handelsnaam van Travel Service International 
b.v.[KvK 06091935]
DISCLAIMER: De informatie opgenomen in dit bericht kan vertrouwelijk 
zijn en is uitsluitend bestemd voor de geadresseerde.
Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud niet 
te gebruiken en de afzender direct te informeren door het bericht te 
retourneren.
The information contained in this message may be confidential and is 
intended to be exclusively for the addressee.
Should you receive this message unintentionally, please do not use the 
contents herein and notify the sender immediately by return e-mail.

Re: Object Caching

Posted by Andrus Adamchik <an...@objectstyle.org>.
Yeah, still need to check that one.

On Nov 12, 2009, at 10:43 AM, Hans Pikkemaat wrote:

> Hi,
>
> Yes, the paginated query would indeed be the only way for me to go  
> forward.
> The problem however is that I get the exception I posted earlier.
>
> tx
>
> Hans
>
> Andrus Adamchik wrote:
>> For paginated queries we contemplated a strategy of a list with   
>> constant size of fully resolved objects. I.e. when a page is  
>> swapped  in, some other (LRU?) page is swapped out. We decided  
>> against it, as  in a general case it is hard to consistently  
>> predict which page should  be swapped out.
>>
>> However it should be rather easy to write such a list for a  
>> specific  case with a known access order (e.g. a standard iteration  
>> order). In  fact I would vote to even include such implementation  
>> in Cayenne going  forward.
>>
>> More specifically, you can extend IncrementalFaultList [1],  
>> overriding  'resolveInterval' to swap out previously read pages,  
>> turning them back  into ids. And the good part is that you can use  
>> your extension  directly without any need to modify the rest of  
>> Cayenne.
>>
>> Andrus
>>
>>
>> [1] http://cayenne.apache.org/doc/api/org/apache/cayenne/access/IncrementalFaultList.html
>>
>>
>> On Nov 12, 2009, at 10:07 AM, Hans Pikkemaat wrote:
>>
>>> Hi,
>>>
>>> So this means that if I use a generic query that the query  
>>> results  are always stored
>>> completely in the object store (or the query cache if I configure  
>>> it).
>>>
>>> Objects are returned in a list so as long I have a reference to  
>>> this  list (because I'm
>>> traversing it) these objects are not garbage collected.
>>>
>>> If I use the query cache the full query results are cached. This   
>>> means that I can only
>>> tell it to remove the whole query.
>>>
>>> Effectively this means I'm unable to run a big query and process  
>>> the  results as a stream.
>>> So I cannot process the first results and then somehow make them   
>>> available for
>>> garbage collection.
>>>
>>> The only option I have would be the iterated query but this is  
>>> only  usefull for queries
>>> one 1 table without any relations because it is not possible to  
>>> use  prefetching nor is
>>> it possible to manually construct relations between obects.
>>>
>>> My conclusion here is that cayenne is simply not suitable for  
>>> doing  large batch wise
>>> query processing because of the memory implications.
>>>
>>> tx
>>>
>>> HPI
>>>
>>> Andrus Adamchik wrote:
>>>
>>>> As mentioned in the docs, individual objects and query lists are
>>>> cached independently. Of course query lists contain a subset of   
>>>> cached
>>>> object store objects inside the lists. An object won't get gc'd  
>>>> if it
>>>> is also stored in the query list.
>>>>
>>>> Now list cache expiration is controlled via query cache factory. By
>>>> default this is an LRU map, so as long as the map has enough  
>>>> space to
>>>> hold lists (its capacity == # of lists, not # of objects), the   
>>>> objects
>>>> won't get gc'd.
>>>>
>>>> You can explicitly remove entries from the cache via QueryCache   
>>>> remove
>>>> and removeGroup methods. Or you can use a different  
>>>> QueryCacheFactory
>>>> that implements some custom expiration/cleanup mechanism.
>>>>
>>>> Andrus
>>>>
>>>> On Nov 11, 2009, at 3:43 PM, Hans Pikkemaat wrote:
>>>>
>>>>
>>>>
>>>>> Hi,
>>>>>
>>>>> I use the latest version of cayenne, 3.0b and am experimenting  
>>>>> with
>>>>> the object caching features.
>>>>>
>>>>> The documentation states that committed objects are purged from  
>>>>> the
>>>>> cache because it uses weak references.
>>>>> (http://cayenne.apache.org/doc/individual-object-caching.html)
>>>>>
>>>>> If I however run a query using SQLTemplate which caches the  
>>>>> objects
>>>>> into the dataContext local cache (objectstore),
>>>>> the objects don't seem to be purged at all. If I simply run the
>>>>> query dump the contents using an iterator on the resulting
>>>>> List then the nr of registered objects in the objectstore stays  
>>>>> the
>>>>> same (dataContext.getObjectStore().registeredObjectsCount()).
>>>>> Even if I manually run System.gc() I don't see any changes (I know
>>>>> this can be normal as gc() doesn't guarantee anything)
>>>>>
>>>>> What am I doing wrong? Under which circumstances will cayenne  
>>>>> purge
>>>>> the cache?
>>>>>
>>>>> tx
>>>>>
>>>>> Hans
>>>>>
>>>>>
>>>>>
>>>>
>
>
>


Re: Object Caching

Posted by Hans Pikkemaat <h....@tsi-solutions.nl>.
Hi,

Yes, the paginated query would indeed be the only way for me to go forward.
The problem however is that I get the exception I posted earlier.

tx

Hans

Andrus Adamchik wrote:
> For paginated queries we contemplated a strategy of a list with  
> constant size of fully resolved objects. I.e. when a page is swapped  
> in, some other (LRU?) page is swapped out. We decided against it, as  
> in a general case it is hard to consistently predict which page should  
> be swapped out.
>
> However it should be rather easy to write such a list for a specific  
> case with a known access order (e.g. a standard iteration order). In  
> fact I would vote to even include such implementation in Cayenne going  
> forward.
>
> More specifically, you can extend IncrementalFaultList [1], overriding  
> 'resolveInterval' to swap out previously read pages, turning them back  
> into ids. And the good part is that you can use your extension  
> directly without any need to modify the rest of Cayenne.
>
> Andrus
>
>
> [1] http://cayenne.apache.org/doc/api/org/apache/cayenne/access/IncrementalFaultList.html
>
>
> On Nov 12, 2009, at 10:07 AM, Hans Pikkemaat wrote:
>   
>> Hi,
>>
>> So this means that if I use a generic query that the query results  
>> are always stored
>> completely in the object store (or the query cache if I configure it).
>>
>> Objects are returned in a list so as long I have a reference to this  
>> list (because I'm
>> traversing it) these objects are not garbage collected.
>>
>> If I use the query cache the full query results are cached. This  
>> means that I can only
>> tell it to remove the whole query.
>>
>> Effectively this means I'm unable to run a big query and process the  
>> results as a stream.
>> So I cannot process the first results and then somehow make them  
>> available for
>> garbage collection.
>>
>> The only option I have would be the iterated query but this is only  
>> usefull for queries
>> one 1 table without any relations because it is not possible to use  
>> prefetching nor is
>> it possible to manually construct relations between obects.
>>
>> My conclusion here is that cayenne is simply not suitable for doing  
>> large batch wise
>> query processing because of the memory implications.
>>
>> tx
>>
>> HPI
>>
>> Andrus Adamchik wrote:
>>     
>>> As mentioned in the docs, individual objects and query lists are
>>> cached independently. Of course query lists contain a subset of  
>>> cached
>>> object store objects inside the lists. An object won't get gc'd if it
>>> is also stored in the query list.
>>>
>>> Now list cache expiration is controlled via query cache factory. By
>>> default this is an LRU map, so as long as the map has enough space to
>>> hold lists (its capacity == # of lists, not # of objects), the  
>>> objects
>>> won't get gc'd.
>>>
>>> You can explicitly remove entries from the cache via QueryCache  
>>> remove
>>> and removeGroup methods. Or you can use a different QueryCacheFactory
>>> that implements some custom expiration/cleanup mechanism.
>>>
>>> Andrus
>>>
>>> On Nov 11, 2009, at 3:43 PM, Hans Pikkemaat wrote:
>>>
>>>
>>>       
>>>> Hi,
>>>>
>>>> I use the latest version of cayenne, 3.0b and am experimenting with
>>>> the object caching features.
>>>>
>>>> The documentation states that committed objects are purged from the
>>>> cache because it uses weak references.
>>>> (http://cayenne.apache.org/doc/individual-object-caching.html)
>>>>
>>>> If I however run a query using SQLTemplate which caches the objects
>>>> into the dataContext local cache (objectstore),
>>>> the objects don't seem to be purged at all. If I simply run the
>>>> query dump the contents using an iterator on the resulting
>>>> List then the nr of registered objects in the objectstore stays the
>>>> same (dataContext.getObjectStore().registeredObjectsCount()).
>>>> Even if I manually run System.gc() I don't see any changes (I know
>>>> this can be normal as gc() doesn't guarantee anything)
>>>>
>>>> What am I doing wrong? Under which circumstances will cayenne purge
>>>> the cache?
>>>>
>>>> tx
>>>>
>>>> Hans
>>>>
>>>>
>>>>         
>>>       



Re: Object Caching

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Nov 12, 2009, at 10:07 AM, Hans Pikkemaat wrote:

> The only option I have would be the iterated query but this is only  
> usefull for queries
> one 1 table without any relations because it is not possible to use  
> prefetching nor is
> it possible to manually construct relations between obects.

Also something I wouldn't mind seeing added to Cayenne. All the basic  
algorithms to build an object tree from a single data row are there.  
Just need to wrap them in user-friendly API. But for now in a prefetch  
case unfortunately you'd have to stay with DataRows if you are using  
iterated query.

Andrus


Re: Object Caching

Posted by Andrus Adamchik <an...@objectstyle.org>.
For paginated queries we contemplated a strategy of a list with  
constant size of fully resolved objects. I.e. when a page is swapped  
in, some other (LRU?) page is swapped out. We decided against it, as  
in a general case it is hard to consistently predict which page should  
be swapped out.

However it should be rather easy to write such a list for a specific  
case with a known access order (e.g. a standard iteration order). In  
fact I would vote to even include such implementation in Cayenne going  
forward.

More specifically, you can extend IncrementalFaultList [1], overriding  
'resolveInterval' to swap out previously read pages, turning them back  
into ids. And the good part is that you can use your extension  
directly without any need to modify the rest of Cayenne.

Andrus


[1] http://cayenne.apache.org/doc/api/org/apache/cayenne/access/IncrementalFaultList.html


On Nov 12, 2009, at 10:07 AM, Hans Pikkemaat wrote:
> Hi,
>
> So this means that if I use a generic query that the query results  
> are always stored
> completely in the object store (or the query cache if I configure it).
>
> Objects are returned in a list so as long I have a reference to this  
> list (because I'm
> traversing it) these objects are not garbage collected.
>
> If I use the query cache the full query results are cached. This  
> means that I can only
> tell it to remove the whole query.
>
> Effectively this means I'm unable to run a big query and process the  
> results as a stream.
> So I cannot process the first results and then somehow make them  
> available for
> garbage collection.
>
> The only option I have would be the iterated query but this is only  
> usefull for queries
> one 1 table without any relations because it is not possible to use  
> prefetching nor is
> it possible to manually construct relations between obects.
>
> My conclusion here is that cayenne is simply not suitable for doing  
> large batch wise
> query processing because of the memory implications.
>
> tx
>
> HPI
>
> Andrus Adamchik wrote:
>>
>> As mentioned in the docs, individual objects and query lists are
>> cached independently. Of course query lists contain a subset of  
>> cached
>> object store objects inside the lists. An object won't get gc'd if it
>> is also stored in the query list.
>>
>> Now list cache expiration is controlled via query cache factory. By
>> default this is an LRU map, so as long as the map has enough space to
>> hold lists (its capacity == # of lists, not # of objects), the  
>> objects
>> won't get gc'd.
>>
>> You can explicitly remove entries from the cache via QueryCache  
>> remove
>> and removeGroup methods. Or you can use a different QueryCacheFactory
>> that implements some custom expiration/cleanup mechanism.
>>
>> Andrus
>>
>> On Nov 11, 2009, at 3:43 PM, Hans Pikkemaat wrote:
>>
>>
>>> Hi,
>>>
>>> I use the latest version of cayenne, 3.0b and am experimenting with
>>> the object caching features.
>>>
>>> The documentation states that committed objects are purged from the
>>> cache because it uses weak references.
>>> (http://cayenne.apache.org/doc/individual-object-caching.html)
>>>
>>> If I however run a query using SQLTemplate which caches the objects
>>> into the dataContext local cache (objectstore),
>>> the objects don't seem to be purged at all. If I simply run the
>>> query dump the contents using an iterator on the resulting
>>> List then the nr of registered objects in the objectstore stays the
>>> same (dataContext.getObjectStore().registeredObjectsCount()).
>>> Even if I manually run System.gc() I don't see any changes (I know
>>> this can be normal as gc() doesn't guarantee anything)
>>>
>>> What am I doing wrong? Under which circumstances will cayenne purge
>>> the cache?
>>>
>>> tx
>>>
>>> Hans
>>>
>>>
>>
>>
>
> -- 
> <tsi_logo.png>
> TSi Solutions
> Neptunusstraat 25
> 7521 WC Enschede
>
> Tel. +31 (0)88 - 25 00 000
> Fax. +31 (0)88 - 25 00 122
> Hans Pikkemaat
> Java Developer (Services Team)
> E-mail: h.pikkemaat@tsi-solutions.nl
>
> www.tsi-solutions.nl
> www.toeristiek.nl
> <tsi_sunset.png>
> <tsi_pictos.png>
> 10 jaar TSi Solutions
> ... marktleider in het automatiseren en outsourcen van werkprocessen  
> in de reisbranche
> ... toonaangevende partij voor het verzamelen, structureren en  
> beschikbaarstellen van reiscontent
> ... Reisrevue Innovatieveer 2008 - Veervolle vermelding
> ... Winnaar Reisrevue Innovatieveer 2009
> ... Top 20 positie in 2008 Deloitte Technology Fast50 Nederland
> ... Top 10 positie in 2009 Deloitte Technology Fast50 Benelux
> ... genomineerd voor Technology 500 EMEA 2009
> TSi Solutions is de handelsnaam van Travel Service International b.v. 
> [KvK 06091935]
> DISCLAIMER: De informatie opgenomen in dit bericht kan vertrouwelijk  
> zijn en is uitsluitend bestemd voor de geadresseerde.
> Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud  
> niet te gebruiken en de afzender direct te informeren door het  
> bericht te retourneren.
> The information contained in this message may be confidential and is  
> intended to be exclusively for the addressee.
> Should you receive this message unintentionally, please do not use  
> the contents herein and notify the sender immediately by return e- 
> mail.


Re: Object Caching

Posted by Hans Pikkemaat <h....@tsi-solutions.nl>.
Hi,

So this means that if I use a generic query that the query results are 
always stored
completely in the object store (or the query cache if I configure it).

Objects are returned in a list so as long I have a reference to this 
list (because I'm
traversing it) these objects are not garbage collected.

If I use the query cache the full query results are cached. This means 
that I can only
tell it to remove the whole query.

Effectively this means I'm unable to run a big query and process the 
results as a stream.
So I cannot process the first results and then somehow make them 
available for
garbage collection.

The only option I have would be the iterated query but this is only 
usefull for queries
one 1 table without any relations because it is not possible to use 
prefetching nor is
it possible to manually construct relations between obects.

My conclusion here is that cayenne is simply not suitable for doing 
large batch wise
query processing because of the memory implications.

tx

HPI

Andrus Adamchik wrote:
> As mentioned in the docs, individual objects and query lists are  
> cached independently. Of course query lists contain a subset of cached  
> object store objects inside the lists. An object won't get gc'd if it  
> is also stored in the query list.
>
> Now list cache expiration is controlled via query cache factory. By  
> default this is an LRU map, so as long as the map has enough space to  
> hold lists (its capacity == # of lists, not # of objects), the objects  
> won't get gc'd.
>
> You can explicitly remove entries from the cache via QueryCache remove  
> and removeGroup methods. Or you can use a different QueryCacheFactory  
> that implements some custom expiration/cleanup mechanism.
>
> Andrus
>
> On Nov 11, 2009, at 3:43 PM, Hans Pikkemaat wrote:
>
>   
>> Hi,
>>
>> I use the latest version of cayenne, 3.0b and am experimenting with  
>> the object caching features.
>>
>> The documentation states that committed objects are purged from the  
>> cache because it uses weak references.
>> (http://cayenne.apache.org/doc/individual-object-caching.html)
>>
>> If I however run a query using SQLTemplate which caches the objects  
>> into the dataContext local cache (objectstore),
>> the objects don't seem to be purged at all. If I simply run the  
>> query dump the contents using an iterator on the resulting
>> List then the nr of registered objects in the objectstore stays the  
>> same (dataContext.getObjectStore().registeredObjectsCount()).
>> Even if I manually run System.gc() I don't see any changes (I know  
>> this can be normal as gc() doesn't guarantee anything)
>>
>> What am I doing wrong? Under which circumstances will cayenne purge  
>> the cache?
>>
>> tx
>>
>> Hans
>>
>>     
>
>   

-- 
	TSi Solutions
Neptunusstraat 25
7521 WC Enschede

Tel. +31 (0)88 - 25 00 000
Fax. +31 (0)88 - 25 00 122
Hans Pikkemaat
Java Developer (Services Team)
	E-mail: h.pikkemaat@tsi-solutions.nl <ma...@tsi-solutions.nl>
  	www.tsi-solutions.nl <http://www.tsi-solutions.nl/>
www.toeristiek.nl <http://www.toeristiek.nl/>
	

10 jaar TSi Solutions
... marktleider in het automatiseren en outsourcen van werkprocessen in 
de reisbranche
... toonaangevende partij voor het verzamelen, structureren en 
beschikbaarstellen van reiscontent
... Reisrevue Innovatieveer 2008 - Veervolle vermelding
... Winnaar Reisrevue Innovatieveer 2009
... Top 20 positie in 2008 Deloitte Technology Fast50 Nederland
... Top 10 positie in 2009 Deloitte Technology Fast50 Benelux
... genomineerd voor Technology 500 EMEA 2009
TSi Solutions is de handelsnaam van Travel Service International 
b.v.[KvK 06091935]
DISCLAIMER: De informatie opgenomen in dit bericht kan vertrouwelijk 
zijn en is uitsluitend bestemd voor de geadresseerde.
Indien u dit bericht onterecht ontvangt, wordt u verzocht de inhoud niet 
te gebruiken en de afzender direct te informeren door het bericht te 
retourneren.
The information contained in this message may be confidential and is 
intended to be exclusively for the addressee.
Should you receive this message unintentionally, please do not use the 
contents herein and notify the sender immediately by return e-mail.

Re: Object Caching

Posted by Andrus Adamchik <an...@objectstyle.org>.
As mentioned in the docs, individual objects and query lists are  
cached independently. Of course query lists contain a subset of cached  
object store objects inside the lists. An object won't get gc'd if it  
is also stored in the query list.

Now list cache expiration is controlled via query cache factory. By  
default this is an LRU map, so as long as the map has enough space to  
hold lists (its capacity == # of lists, not # of objects), the objects  
won't get gc'd.

You can explicitly remove entries from the cache via QueryCache remove  
and removeGroup methods. Or you can use a different QueryCacheFactory  
that implements some custom expiration/cleanup mechanism.

Andrus

On Nov 11, 2009, at 3:43 PM, Hans Pikkemaat wrote:

> Hi,
>
> I use the latest version of cayenne, 3.0b and am experimenting with  
> the object caching features.
>
> The documentation states that committed objects are purged from the  
> cache because it uses weak references.
> (http://cayenne.apache.org/doc/individual-object-caching.html)
>
> If I however run a query using SQLTemplate which caches the objects  
> into the dataContext local cache (objectstore),
> the objects don't seem to be purged at all. If I simply run the  
> query dump the contents using an iterator on the resulting
> List then the nr of registered objects in the objectstore stays the  
> same (dataContext.getObjectStore().registeredObjectsCount()).
> Even if I manually run System.gc() I don't see any changes (I know  
> this can be normal as gc() doesn't guarantee anything)
>
> What am I doing wrong? Under which circumstances will cayenne purge  
> the cache?
>
> tx
>
> Hans
>