dev@grizzly.java.net

Re: Grizzly 2.0: monitoring memory consumption

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Fri, 19 Mar 2010 22:43:01 +0100

Hi Igor,

> looks good to me, except for the humongous class names. Is it really
> necessary to call it MemoryManagerMonitoringProbe? Won't simply
> MemoryProbe be enough? IMO Manager has nothing to do with a probe and
> Monitoring is already implied.
Agree.


> And one last thing, I'm not a big fan of static state, so I naturally
> dislike "TransportFactory.getInstance().setDefaultMemoryManager(mm);".
> Of course this problem is not specific to just this piece of code, but
> to grizzly in general. I think that the lack of a dependency injection
> and a common bootstrapping mechanism is going to bite the project
> sooner or later and for that reason addressing this issue should
> become a priority for 2.0.
Agree again, though in this specific case it's not probably
applicable. You're right we set memory manager statically to
TransportFactory. But this value is just default one.
Each Transport, created by TransportFactory will be able to change
that default value by calling dynamic transport.setMemoryManager(...)
method.

But in general, I agree about bootstrapping and will appreciate ideas
on its improvement.

Thanks.

WBR,
Alexey.

>
> /i
>
> On Fri, Mar 19, 2010 at 10:45 AM, Oleksiy Stashok
> <Oleksiy.Stashok_at_sun.com> wrote:
>> Hi,
>>
>> I've implemented simple interface MemoryManagerMonitoringProbe,
>> using which
>> it's possible to get statistics on Grizzly memory consumption.
>> For example:
>>
>> MyMemoryMonitoringProbe probe = new MyMemoryMonitoringProbe();
>> DefaultMemoryManager mm = new DefaultMemoryManager(probe);
>>
>> TransportFactory.getInstance().setDefaultMemoryManager(mm);
>>
>> // Start Grizzly
>> ....................
>>
>> // Log the memory monitoring probe statistic
>> log(probe.toString());
>>
>> //////////// Simple monitoring probe implementation
>>
>> public static class MyMemoryMonitoringProbe implements
>> MemoryManagerMonitoringProbe {
>> private final AtomicLong allocatedNew = new AtomicLong();
>> private final AtomicLong allocatedFromPool = new AtomicLong();
>> private final AtomicLong releasedToPool = new AtomicLong();
>>
>> public void allocateNewBufferEvent(int i) {
>> allocatedNew.addAndGet(i);
>> }
>>
>> public void allocateBufferFromPoolEvent(int i) {
>> allocatedFromPool.addAndGet(i);
>> }
>>
>> public void releaseBufferToPoolEvent(int i) {
>> releasedToPool.addAndGet(i);
>> }
>>
>> @Override
>> public String toString() {
>> StringBuilder sb = new StringBuilder();
>> sb.append("allocated-memory=").append(allocatedNew.get());
>> sb.append("
>> allocated-from-pool=").append(allocatedFromPool.get());
>> sb.append(" released-to-
>> pool=").append(releasedToPool.get());
>>
>> return sb.toString();
>> }
>> }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
>