Is CacheMetrics.getCachePuts() method returns correct result?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Is CacheMetrics.getCachePuts() method returns correct result?

Pavel Konstantinov
Test case:
Two nodes with partitioned cache with 1 backup.
I do Put() 3 times with unique keys.
Then do cache.metrics.getCachePuts() and got value 6.
If backups=2 and nodes=3 then getCachePuts()=9.
I'm confused, I do 3 puts, but get the different result from getCachePuts().

--

Pavel
Reply | Threaded
Open this post in threaded view
|

Re: Is CacheMetrics.getCachePuts() method returns correct result?

Andrey Gura
Pavel,

it's correct behaviour. See simple test case for illustration:

        IgniteCache cache = grid(0).cache(null);

        long cnt = 0;

        while (true) {
            cache.put(cnt++, 1);

            Thread.sleep(1000); // Waiting for heartbeat message and
metrics update

            CacheMetrics metrics = cache.metrics();

            assertEquals(cnt, metrics.getCachePuts());
        }

This cycle will run infinitely because cache.metrics() returns data for one
particular cache node and amount of puts and iterations are equal.

If we change the code above and will get metrics for cluster group (e.g.
CacheMetrics metrics =
cache.metrics(grid(0).cluster().forCacheNodes(null))) then test will fail
because each put operation actually performs on primary node and on every
backup node. In this case getCachePuts() returns sum of put operation for
all cache nodes.


On Thu, May 21, 2015 at 12:17 PM, Pavel Konstantinov <
[hidden email]> wrote:

> Test case:
> Two nodes with partitioned cache with 1 backup.
> I do Put() 3 times with unique keys.
> Then do cache.metrics.getCachePuts() and got value 6.
> If backups=2 and nodes=3 then getCachePuts()=9.
> I'm confused, I do 3 puts, but get the different result from
> getCachePuts().
>
> --
>
> Pavel
>



--
Andrey Gura
GridGain Systems, Inc.
www.gridgain.com