Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Object pooling

Reply
Thread Tools

Object pooling

 
 
Tom Anderson
Guest
Posts: n/a
 
      09-19-2010
Hi all,

I have some heavyweight objects that i would like to try pooling.

To be specific, they're JAX-WS (actually JBossWS) Service (and/or port)
objects. My observations so far are that they take hundreds of
milliseconds to make (if you count instantiation of the service,
instantiation of the port, and extra time taken the first time a method on
the port is called, it seems to be 200-800 ms, depending), and that the
spec doesn't guarantee that they're threadsafe (and as it happens, i
believe that in the JBossWS implementation, neither the service nor the
port is threadsafe).

That may not be that much time in the grand scheme of things, but some
guys in the sort of ops-infrastructure-architecture part of the project
are making worried noises about performance of the web service interfaces,
and i'd like to be able to reassure them.

I know the modern warnings about pooling, but this seems like a case where
it could be justified. Does that sound right?

So, what's the state of the art in object pooling? My default starting
point is Commons pooling:

http://commons.apache.org/pool/

But i note that it doesn't do generics. I would really like something that
does generics. I could wrap a generic wrapper round it fairly easily, but
i'd rather not have to. So, are there any other pooling implementations
around which use generics, or are otherwise preferable?

Thanks,
tom

--
No man ever steps in the same river twice, for it's not the same river
and he's not the same man. -- Heraclitus
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      09-19-2010
On 19.09.2010 15:49, Tom Anderson wrote:

> I have some heavyweight objects that i would like to try pooling.
>
> To be specific, they're JAX-WS (actually JBossWS) Service (and/or port)
> objects. My observations so far are that they take hundreds of
> milliseconds to make (if you count instantiation of the service,
> instantiation of the port, and extra time taken the first time a method
> on the port is called, it seems to be 200-800 ms, depending), and that
> the spec doesn't guarantee that they're threadsafe (and as it happens, i
> believe that in the JBossWS implementation, neither the service nor the
> port is threadsafe).
>
> That may not be that much time in the grand scheme of things, but some
> guys in the sort of ops-infrastructure-architecture part of the project
> are making worried noises about performance of the web service
> interfaces, and i'd like to be able to reassure them.
>
> I know the modern warnings about pooling, but this seems like a case
> where it could be justified. Does that sound right?
>
> So, what's the state of the art in object pooling? My default starting
> point is Commons pooling:
>
> http://commons.apache.org/pool/
>
> But i note that it doesn't do generics. I would really like something
> that does generics. I could wrap a generic wrapper round it fairly
> easily, but i'd rather not have to. So, are there any other pooling
> implementations around which use generics, or are otherwise preferable?


Since you are using web services which is a pretty much standard way of
accessing business logic I would expect some prepackaged solutions to be
available. If not, you could wrap your client code in a JCA connector
which then will be pooled almost automatically by your application
container (at least if it's JBoss but I am pretty sure that other's have
similar functionality).

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      09-19-2010
On 9/19/2010 9:49 AM, Tom Anderson wrote:
>
> I have some heavyweight objects that i would like to try pooling.
>
> To be specific, they're JAX-WS (actually JBossWS) Service (and/or port)
> objects. My observations so far are that they take hundreds of
> milliseconds to make (if you count instantiation of the service,
> instantiation of the port, and extra time taken the first time a method
> on the port is called, it seems to be 200-800 ms, depending), and that
> the spec doesn't guarantee that they're threadsafe (and as it happens, i
> believe that in the JBossWS implementation, neither the service nor the
> port is threadsafe).
> [...]
> I know the modern warnings about pooling, but this seems like a case
> where it could be justified. Does that sound right?


Yes. You're not really pooling the objects per se, but the
associated externals (ports, services, ...) that go with them, and
the investment in setting them up. It sounds very much like pooling
database connections or the like, entirely defensible.

To put it another way: When did "cache" become a dirty word?

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-19-2010
Eric Sosman wrote:
> To put it another way: When did "cache" become a dirty word?


Around when "cash" did.

The problem is the same with both - the real thing is great but there are too
many pretenders. People tire of fairy gold and become disillusioned.

On one recent project my rule of thumb was, "Anything that claims to be a
cache isn't."

Some so-called "caches" were slower than the operation they buffered, under
multi-threaded production loads that is, not single-threaded development
environments. Other "caches" sit on top of OS or hardware caches that already
are fast enough.

Such experiences are common enough that the pendulum has swung. People hear
"Premature optimization is the root of all evil," as if it were "Optimization
is the root of all evil."

They are as wrong as their antagonists; obsessive knee-jerk anti-optimization
is as bad as obsessive knee-jerk failed attempts to optimize. The art, and
the measure of one's intelligence and wisdom, lies in the choice of when and
where to optimize, based on evidence from reality.

--
Lew
<http://www.indopedia.org/The_Life_of_Brian.html>
Brian (to adoring crowd): You've got to think for yourself! You're all
individuals!
Crowd (in unison): Yes, we're all individuals!
Brian (to adoring crowd): You're all different!
Crowd (in unison): Yes, we're all different!
Single voice (from within the crowd): I'm not.
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-19-2010
On Sun, 19 Sep 2010, Eric Sosman wrote:

> On 9/19/2010 9:49 AM, Tom Anderson wrote:
>
>> I have some heavyweight objects that i would like to try pooling.
>>
>> To be specific, they're JAX-WS (actually JBossWS) Service (and/or port)
>> objects. My observations so far are that they take hundreds of
>> milliseconds to make (if you count instantiation of the service,
>> instantiation of the port, and extra time taken the first time a method
>> on the port is called, it seems to be 200-800 ms, depending), and that
>> the spec doesn't guarantee that they're threadsafe (and as it happens, i
>> believe that in the JBossWS implementation, neither the service nor the
>> port is threadsafe).
>> [...]
>> I know the modern warnings about pooling, but this seems like a case
>> where it could be justified. Does that sound right?

>
> Yes. You're not really pooling the objects per se, but the
> associated externals (ports, services, ...) that go with them, and the
> investment in setting them up. It sounds very much like pooling
> database connections or the like, entirely defensible.


Pooling the investment is an excellent way of looking at it, yes.

I'd be interested to know where the time taken to build these objects is
spent - i know initialising the service involves reading and parsing the
WSDL, and then doing something or other based on that, so i imagine that's
quite a bit of it.

> To put it another way: When did "cache" become a dirty word?


After Thatcherism died out.

tom

--
bad bad good
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-19-2010
On Sun, 19 Sep 2010, Robert Klemme wrote:

> On 19.09.2010 15:49, Tom Anderson wrote:
>
>> I have some heavyweight objects that i would like to try pooling.
>>
>> To be specific, they're JAX-WS (actually JBossWS) Service (and/or port)
>> objects. My observations so far are that they take hundreds of
>> milliseconds to make (if you count instantiation of the service,
>> instantiation of the port, and extra time taken the first time a method
>> on the port is called, it seems to be 200-800 ms, depending), and that
>> the spec doesn't guarantee that they're threadsafe (and as it happens,
>> i believe that in the JBossWS implementation, neither the service nor
>> the port is threadsafe).

>
> Since you are using web services which is a pretty much standard way of
> accessing business logic I would expect some prepackaged solutions to be
> available.


So would i. I haven't come across any, though.

> If not, you could wrap your client code in a JCA connector which then
> will be pooled almost automatically by your application container


Man, it's all JCA today! This is something that would make a sensible
general-purpose tool, i suppose. How would you access it from application
code? Bind some kind of ServicePool into the JNDI namespace and look it
up? Or bind a PoolableService which gives out a different instance every
time it's looked up?

tom

--
If it ain't broke, open it up and see what makes it so bloody special.
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-19-2010
On 19-09-2010 09:49, Tom Anderson wrote:
> I have some heavyweight objects that i would like to try pooling.
>
> To be specific, they're JAX-WS (actually JBossWS) Service (and/or port)
> objects. My observations so far are that they take hundreds of
> milliseconds to make (if you count instantiation of the service,
> instantiation of the port, and extra time taken the first time a method
> on the port is called, it seems to be 200-800 ms, depending), and that
> the spec doesn't guarantee that they're threadsafe (and as it happens, i
> believe that in the JBossWS implementation, neither the service nor the
> port is threadsafe).
>
> That may not be that much time in the grand scheme of things, but some
> guys in the sort of ops-infrastructure-architecture part of the project
> are making worried noises about performance of the web service
> interfaces, and i'd like to be able to reassure them.
>
> I know the modern warnings about pooling, but this seems like a case
> where it could be justified. Does that sound right?
>
> So, what's the state of the art in object pooling? My default starting
> point is Commons pooling:
>
> http://commons.apache.org/pool/
>
> But i note that it doesn't do generics. I would really like something
> that does generics. I could wrap a generic wrapper round it fairly
> easily, but i'd rather not have to. So, are there any other pooling
> implementations around which use generics, or are otherwise preferable?


Pooling is an anti-pattern today for simple "just allocate memory
and initialize values without interacting with anything" objects.

Pools are completely standard for database connections.

I would go for the Apache Commons Pools. They work fine. And
I doubt that you will need to interact so many places that
a little bit of casting would be a problem.

Arne

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-19-2010
On 19-09-2010 14:13, Tom Anderson wrote:
> On Sun, 19 Sep 2010, Robert Klemme wrote:
>> On 19.09.2010 15:49, Tom Anderson wrote:
>>> I have some heavyweight objects that i would like to try pooling.
>>>
>>> To be specific, they're JAX-WS (actually JBossWS) Service (and/or
>>> port) objects. My observations so far are that they take hundreds of
>>> milliseconds to make (if you count instantiation of the service,
>>> instantiation of the port, and extra time taken the first time a
>>> method on the port is called, it seems to be 200-800 ms, depending),
>>> and that the spec doesn't guarantee that they're threadsafe (and as
>>> it happens, i believe that in the JBossWS implementation, neither the
>>> service nor the port is threadsafe).

>>
>> Since you are using web services which is a pretty much standard way
>> of accessing business logic I would expect some prepackaged solutions
>> to be available.

>
> So would i. I haven't come across any, though.


Axis allows you to define the scope of the service to request,
session or application.

The last will reuse. But it does require the service methods
to be individually thread safe. If that does not work for
you, then you need to look for another solution.

>> If not, you could wrap your client code in a JCA connector which then
>> will be pooled almost automatically by your application container

>
> Man, it's all JCA today!


JCA does not seem to be a good fit for your requirement. You don't
need anything JCA specific. And you can do pools without it.

> This is something that would make a sensible
> general-purpose tool, i suppose. How would you access it from
> application code? Bind some kind of ServicePool into the JNDI namespace
> and look it up?


Yes.

Arne
 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      09-20-2010
On 19 Sep., 23:24, Arne Vajh°j <(E-Mail Removed)> wrote:
> On 19-09-2010 14:13, Tom Anderson wrote:
>
>
>
> > On Sun, 19 Sep 2010, Robert Klemme wrote:
> >> On 19.09.2010 15:49, Tom Anderson wrote:
> >>> I have some heavyweight objects that i would like to try pooling.

>
> >>> To be specific, they're JAX-WS (actually JBossWS) Service (and/or
> >>> port) objects. My observations so far are that they take hundreds of
> >>> milliseconds to make (if you count instantiation of the service,
> >>> instantiation of the port, and extra time taken the first time a
> >>> method on the port is called, it seems to be 200-800 ms, depending),
> >>> and that the spec doesn't guarantee that they're threadsafe (and as
> >>> it happens, i believe that in the JBossWS implementation, neither the
> >>> service nor the port is threadsafe).

>
> >> Since you are using web services which is a pretty much standard way
> >> of accessing business logic I would expect some prepackaged solutions
> >> to be available.

>
> > So would i. I haven't come across any, though.

>
> Axis allows you to define the scope of the service to request,
> session or application.
>
> The last will reuse. But it does require the service methods
> to be individually thread safe. If that does not work for
> you, then you need to look for another solution.


That means you either create a bottleneck or have to do the pooling
internally.

> >> If not, you could wrap your client code in a JCA connector which then
> >> will be pooled almost automatically by your application container

>
> > Man, it's all JCA today!

>
> JCA does not seem to be a good fit for your requirement. You don't
> need anything JCA specific. And you can do pools without it.


Why not? Since you are talking to a remote system and _if_ there is
no built in solution in the app server used, then JCA seems like the
exact fit. Basically, talking to remote systems and exchanging
information is exactly what JCA was created for. And you can even
make it transactional. What makes you say it's not a good fit?

Kind regards

robert
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      09-21-2010
On 20-09-2010 05:09, Robert Klemme wrote:
> On 19 Sep., 23:24, Arne Vajh°j<(E-Mail Removed)> wrote:
>> On 19-09-2010 14:13, Tom Anderson wrote:
>>> On Sun, 19 Sep 2010, Robert Klemme wrote:
>>>> On 19.09.2010 15:49, Tom Anderson wrote:
>>>>> I have some heavyweight objects that i would like to try pooling.

>>
>>>>> To be specific, they're JAX-WS (actually JBossWS) Service (and/or
>>>>> port) objects. My observations so far are that they take hundreds of
>>>>> milliseconds to make (if you count instantiation of the service,
>>>>> instantiation of the port, and extra time taken the first time a
>>>>> method on the port is called, it seems to be 200-800 ms, depending),
>>>>> and that the spec doesn't guarantee that they're threadsafe (and as
>>>>> it happens, i believe that in the JBossWS implementation, neither the
>>>>> service nor the port is threadsafe).

>>
>>>> Since you are using web services which is a pretty much standard way
>>>> of accessing business logic I would expect some prepackaged solutions
>>>> to be available.

>>
>>> So would i. I haven't come across any, though.

>>
>> Axis allows you to define the scope of the service to request,
>> session or application.
>>
>> The last will reuse. But it does require the service methods
>> to be individually thread safe. If that does not work for
>> you, then you need to look for another solution.

>
> That means you either create a bottleneck or have to do the pooling
> internally.


No.

If the methods are thread safe you can make parallel calls
on the same object.

>>>> If not, you could wrap your client code in a JCA connector which then
>>>> will be pooled almost automatically by your application container

>>
>>> Man, it's all JCA today!

>>
>> JCA does not seem to be a good fit for your requirement. You don't
>> need anything JCA specific. And you can do pools without it.

>
> Why not? Since you are talking to a remote system and _if_ there is
> no built in solution in the app server used, then JCA seems like the
> exact fit. Basically, talking to remote systems and exchanging
> information is exactly what JCA was created for. And you can even
> make it transactional. What makes you say it's not a good fit?


JCA is for connecting to systems.

But you don't need it for the standard supported protocols: EJB,
Web Service, JMS etc..

And you don't need any of the special privileges of JCA: using
JNI, starting threads, listening to sockets etc..

And the CCI interface would make the API more cumbersome
not less cumbersome.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does object pooling *ever* make sense? Chris Java 26 02-10-2007 09:34 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
connection pooling error Chris Szabo ASP .Net 6 08-19-2003 07:19 PM
.net thread pooling problem Gary ASP .Net 0 08-07-2003 04:35 AM
connection pooling Trevor Hartman ASP .Net 2 07-28-2003 07:58 PM



Advertisments