Andrus Adamchik | 1 May 2010 07:09
Favicon

Re: Large number of EventManager threads causing OutOfMemoryException

I don't think running things on the same server vs. separate server is  
an issue. Hw is your business tier implemented though? Is that an EJB  
or a web app? Something in its lifecycle makes Cayenne start multiple  
times and this is what you need to figure out.

Andrus

On Apr 30, 2010, at 11:14 AM, Victor Leung wrote:

> Hi Andrus,
>
> Thank you for your prompt and insightful reply!
>
> Looking through the thread dumps as suggested, it definitely seems  
> like we
> are starting multiple Cayenne stacks / EventManagers -- on point  
> (1), the
> number after the last dash is rather low, and on point (2), the  
> address of
> the lock are pretty much all different.
>
> In our current test environment (where the problem is occurring), we  
> have
> deployed both the web tier and the business tier as separate EARs on  
> the
> same server. As mentioned earlier, communication between the two  
> tiers is
> through the use of Cayenne Web Service. Is this a supported  
> configuration,
> or do we need to deploy the two EARs on separate servers?
(Continue reading)

Andrus Adamchik | 1 May 2010 07:12
Favicon

Re: Large number of EventManager threads causing OutOfMemoryException

Or actually, client can be a problem as well. Each ClientChannel that  
you create would start an EventManager. So you may want to do  
ClientChannel.getEventManager().shutdown() before a ClientChannel goes  
out of scope.

Andrus

On May 1, 2010, at 1:09 PM, Andrus Adamchik wrote:

> I don't think running things on the same server vs. separate server  
> is an issue. Hw is your business tier implemented though? Is that an  
> EJB or a web app? Something in its lifecycle makes Cayenne start  
> multiple times and this is what you need to figure out.
>
> Andrus
>
> On Apr 30, 2010, at 11:14 AM, Victor Leung wrote:
>
>> Hi Andrus,
>>
>> Thank you for your prompt and insightful reply!
>>
>> Looking through the thread dumps as suggested, it definitely seems  
>> like we
>> are starting multiple Cayenne stacks / EventManagers -- on point  
>> (1), the
>> number after the last dash is rather low, and on point (2), the  
>> address of
>> the lock are pretty much all different.
>>
(Continue reading)

Andrus Adamchik | 2 May 2010 05:42
Favicon

Re: servlet filter and the Configuration

On May 1, 2010, at 12:07 AM, MGargano <at> escholar.com wrote:

> Okay,
>
>        So I think I've made some progress since my question  
> yesterday.  I
> have a bean in Spring that is a ConfigurationFactory.  It returns a
> singleton and the dataSource can be obtained from that.  Now I just  
> need
> to get that configuration loaded on web startup.  I guess I need to  
> write
> a filter because all the filters (the one in cayenne and the click
> project) create a new shared configuration on init with  
> ServletUtil.  I
> guess I want to override those init()'s and get a reference to my  
> bean and
> call initialize() on it directly.  Is that correct?

Sounds about right.

> When I do this will that Configuration become the shared  
> configuration?  If not how do I make
> it the shared configuration?

It does as long as either of the following is called either in your  
Filter or your Spring factory for Configuration:

Configuration.initializeSharedConfiguration(conf);

or
(Continue reading)

Victor Leung | 2 May 2010 14:22
Favicon

Re: Large number of EventManager threads causing OutOfMemoryException

Hi Andrus,

Thank you -- you've hit the nail right on the head!

In our web tier, we've been starting up a new ClientChannel when creating
each session-specific CayenneContext. I've since changed the code so that
all CayenneContexts are now created using a shared ClientChannel instance
(Singleton pattern).

I've run through a couple of user scenarios, and the server's thread count
seem to have stabilised. We'll try and run through some soak testing in the
next 2 weeks, but I'm pretty confident that we've resolved the problem.

Thank you once again.

Cheers,
Vic

On Sat, May 1, 2010 at 3:12 PM, Andrus Adamchik <andrus <at> objectstyle.org>wrote:

> Or actually, client can be a problem as well. Each ClientChannel that you
> create would start an EventManager. So you may want to do
> ClientChannel.getEventManager().shutdown() before a ClientChannel goes out
> of scope.
>
> Andrus
>
>
>
> On May 1, 2010, at 1:09 PM, Andrus Adamchik wrote:
(Continue reading)

Borut Bolčina | 3 May 2010 13:26
Picon
Gravatar

Old web application needs a second database

Hello,

Our old large web application uses one database and there are a large number
of DataContext.createDataContext(); statements all over the web application
itself and jars it depends on.

Now there is a need to access another database. Currently the Configuration
gets initialized with the first call of createDataContext - there is no
special class which initializes cayenne eagerly. All defaults.

Reading the API (
http://cayenne.apache.org/doc30/api/org/apache/cayenne/access/DataContext.html#createDataContext%28%29)
there is a sentence:

"Factory method that creates and returns a new instance of DataContext based
on default domain."

What is the default domain? I can't find anything in the modeler or in the
cayenne xml configuration file to mark one node as default.

Currently the cayenne.xml comes from one of the external jars, not the web
application itself. Now I will have to create a manually crafted
my-cayenne.xml configuration file which has another data node and initialize
it with something like:

DefaultConfiguration conf = new DefaultConfiguration("my-cayenne.xml");

But I suspect I would have to find all occurances of createDataContext() and
replace it with createDataContext("old-node-name"). I would really like to
avoid that!
(Continue reading)

Andrus Adamchik | 3 May 2010 13:44
Favicon

Re: Old web application needs a second database

"Default" refers to a "default domain" within a single configuration  
instance. You will be working with 2 configuration instances, so both  
will have a "default domain". This also means that your old code can  
stay unchanged, while the new application won't be able to use a  
static method for DataContext creation (either with domain name or  
without it). Instead you will need to write your own factory method  
that gets a hold of "conf", gets its default domain, and creates a  
context from it.

Andrus

On May 3, 2010, at 2:26 PM, Borut Bolčina wrote:

> Hello,
>
> Our old large web application uses one database and there are a  
> large number
> of DataContext.createDataContext(); statements all over the web  
> application
> itself and jars it depends on.
>
> Now there is a need to access another database. Currently the  
> Configuration
> gets initialized with the first call of createDataContext - there is  
> no
> special class which initializes cayenne eagerly. All defaults.
>
> Reading the API (
> http://cayenne.apache.org/doc30/api/org/apache/cayenne/access/DataContext.html#createDataContext%28%29)
> there is a sentence:
(Continue reading)

Borut Bolčina | 3 May 2010 14:12
Picon
Gravatar

Re: Old web application needs a second database

Thanks for quick response,

Why 2 configuration instances? There will be cayenne.xml (with node A) and
my-cayenne.xml (with node A and B) on the classpath. Is that why? Would it
be more convenient if my-cayenne.xml only consist of node B?

I am not sure how to initialize.

-Borut

2010/5/3 Andrus Adamchik <andrus <at> objectstyle.org>

> "Default" refers to a "default domain" within a single configuration
> instance. You will be working with 2 configuration instances, so both will
> have a "default domain". This also means that your old code can stay
> unchanged, while the new application won't be able to use a static method
> for DataContext creation (either with domain name or without it). Instead
> you will need to write your own factory method that gets a hold of "conf",
> gets its default domain, and creates a context from it.
>
> Andrus
>
>
>
> On May 3, 2010, at 2:26 PM, Borut Bolčina wrote:
>
>  Hello,
>>
>> Our old large web application uses one database and there are a large
>> number
(Continue reading)

Andrus Adamchik | 3 May 2010 14:19
Favicon

Re: Old web application needs a second database


On May 3, 2010, at 3:12 PM, Borut Bolčina wrote:

> There will be cayenne.xml (with node A) and
> my-cayenne.xml (with node A and B) on the classpath. Is that why?

Yes.

> I am not sure how to initialize.

#1 is created implicitly when you call  
DataContext.createDataContext(). That's the one returned from  
Configuration.getSharedConfiguration().

#2 you will have to create yourself and store somewhere. E.g. in a  
ServletContext attribute.

DefaultConfiguration conf = new DefaultConfiguration("my-cayenne.xml");
// store it for the app duration soemwhere
...

// later when you need a new context:
Configuration conf = .. // get it from ServletContext or from where  
you put it
return conf.getDomain().createDataContext();

Andrus
Andrus Adamchik | 3 May 2010 14:28
Favicon

Re: Old web application needs a second database

Just to add some perspective (and hopefully not to confuse things  
further), our direction in Cayenne 3.1 is towards scenario #2, and  
getting rid of #1 completely. This way a user decides where his  
Cayenne stack (or multiple Cayenne stacks) is stored and how it is  
accessed.

Andrus

On May 3, 2010, at 3:19 PM, Andrus Adamchik wrote:

>
> On May 3, 2010, at 3:12 PM, Borut Bolčina wrote:
>
>> There will be cayenne.xml (with node A) and
>> my-cayenne.xml (with node A and B) on the classpath. Is that why?
>
> Yes.
>
>> I am not sure how to initialize.
>
> #1 is created implicitly when you call  
> DataContext.createDataContext(). That's the one returned from  
> Configuration.getSharedConfiguration().
>
> #2 you will have to create yourself and store somewhere. E.g. in a  
> ServletContext attribute.
>
> DefaultConfiguration conf = new DefaultConfiguration("my- 
> cayenne.xml");
> // store it for the app duration soemwhere
(Continue reading)

Borut Bolčina | 3 May 2010 14:52
Picon
Gravatar

Re: Old web application needs a second database

Thanks,

So, my-cayenne.xml can only include node B and not both nodes as this new
functionality only needs access to database B.

Is that correct?

-Borut

2010/5/3 Andrus Adamchik <andrus <at> objectstyle.org>

>
> On May 3, 2010, at 3:12 PM, Borut Bolčina wrote:
>
>  There will be cayenne.xml (with node A) and
>> my-cayenne.xml (with node A and B) on the classpath. Is that why?
>>
>
> Yes.
>
>
>  I am not sure how to initialize.
>>
>
> #1 is created implicitly when you call DataContext.createDataContext().
> That's the one returned from Configuration.getSharedConfiguration().
>
> #2 you will have to create yourself and store somewhere. E.g. in a
> ServletContext attribute.
>
(Continue reading)


Gmane