[jira] [Commented] (IGNITE-17043) Performance degradation in Marshaller

2022-06-07 Thread Sergey Kosarev (Jira)


[ 
https://issues.apache.org/jira/browse/IGNITE-17043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17550909#comment-17550909
 ] 

Sergey Kosarev commented on IGNITE-17043:
-

[~sdanilov], thank you for contribution!

> Performance degradation in Marshaller
> -
>
> Key: IGNITE-17043
> URL: https://issues.apache.org/jira/browse/IGNITE-17043
> Project: Ignite
>  Issue Type: Bug
>  Components: cache
>Affects Versions: 2.13, 2.14
>Reporter: Sergey Kosarev
>Assignee: Semyon Danilov
>Priority: Major
>  Time Spent: 3h 10m
>  Remaining Estimate: 0h
>
> There is a problem in ignite-core code in GridHandleTable used inside 
> OptimizedMarshaller where the internal buffers grow in size and does not 
> shrink back.
> What problematic is in GridHandleTable? This is its reset() method that fills 
> arrays in memory. Done once, it's not a big deal. Done a million times for a 
> long buffer, it becomes really long and CPU-consuming.
> Here is simple reproducer (omitting imports for brevity):
> Marshalling of the same object at first takes about 50ms, and then after 
> degradation more than 100 seconds.
> {code:title=DegradationReproducer.java|borderStyle=solid}
> public class DegradationReproducer extends BinaryMarshallerSelfTest {
> @Test
> public void reproduce() throws Exception {
> List> obj = IntStream.range(0, 
> 10).mapToObj(Collections::singletonList).collect(Collectors.toList());
> for (int i = 0; i < 50; i++) {
> Assert.assertThat(measureMarshal(obj), Matchers.lessThan(1000L));
> }
> binaryMarshaller().marshal(
> Collections.singletonList(IntStream.range(0, 
> 1000_000).mapToObj(String::valueOf).collect(Collectors.toList()))
> );
> Assert.assertThat(measureMarshal(obj), Matchers.lessThan(1000L));
> }
> private long measureMarshal(List> obj) throws 
> IgniteCheckedException {
> info("marshalling started ");
> long millis = System.currentTimeMillis();
> binaryMarshaller().marshal(obj);
> millis = System.currentTimeMillis() - millis;
> info("marshalling finished in " + millis + " ms");
> return millis;
> }
> }
> {code}
> on my machine reslust is:
> {quote}
> .
> [2022-05-26 20:58:27,178][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling finished in 
> 39 ms
> [2022-05-26 20:58:27,769][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling started 
> [2022-05-26 21:02:03,588][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling finished in 
> 215819 ms
> [2022-05-26 21:02:03,593][ERROR][main][root] Test failed 
> [test=DegradationReproducer#reproduce[useBinaryArrays = true], 
> duration=218641]
> java.lang.AssertionError: 
> Expected: a value less than <1000L>
>  but: <*215819L*> was greater than <1000L>
>   at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
>   at org.junit.Assert.assertThat(Assert.java:956)
>   at org.junit.Assert.assertThat(Assert.java:923)
>   at 
> org.apache.ignite.internal.binary.DegradationReproducer.reproduce(DegradationReproducer.java:27)
> {quote}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)


[jira] [Commented] (IGNITE-17043) Performance degradation in Marshaller

2022-05-30 Thread Semyon Danilov (Jira)


[ 
https://issues.apache.org/jira/browse/IGNITE-17043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17543909#comment-17543909
 ] 

Semyon Danilov commented on IGNITE-17043:
-

Merged to the master branch

> Performance degradation in Marshaller
> -
>
> Key: IGNITE-17043
> URL: https://issues.apache.org/jira/browse/IGNITE-17043
> Project: Ignite
>  Issue Type: Bug
>  Components: cache
>Affects Versions: 2.13, 2.14
>Reporter: Sergey Kosarev
>Assignee: Semyon Danilov
>Priority: Major
>  Time Spent: 3h 10m
>  Remaining Estimate: 0h
>
> There is a problem in ignite-core code in GridHandleTable used inside 
> OptimizedMarshaller where the internal buffers grow in size and does not 
> shrink back.
> What problematic is in GridHandleTable? This is its reset() method that fills 
> arrays in memory. Done once, it's not a big deal. Done a million times for a 
> long buffer, it becomes really long and CPU-consuming.
> Here is simple reproducer (omitting imports for brevity):
> Marshalling of the same object at first takes about 50ms, and then after 
> degradation more than 100 seconds.
> {code:title=DegradationReproducer.java|borderStyle=solid}
> public class DegradationReproducer extends BinaryMarshallerSelfTest {
> @Test
> public void reproduce() throws Exception {
> List> obj = IntStream.range(0, 
> 10).mapToObj(Collections::singletonList).collect(Collectors.toList());
> for (int i = 0; i < 50; i++) {
> Assert.assertThat(measureMarshal(obj), Matchers.lessThan(1000L));
> }
> binaryMarshaller().marshal(
> Collections.singletonList(IntStream.range(0, 
> 1000_000).mapToObj(String::valueOf).collect(Collectors.toList()))
> );
> Assert.assertThat(measureMarshal(obj), Matchers.lessThan(1000L));
> }
> private long measureMarshal(List> obj) throws 
> IgniteCheckedException {
> info("marshalling started ");
> long millis = System.currentTimeMillis();
> binaryMarshaller().marshal(obj);
> millis = System.currentTimeMillis() - millis;
> info("marshalling finished in " + millis + " ms");
> return millis;
> }
> }
> {code}
> on my machine reslust is:
> {quote}
> .
> [2022-05-26 20:58:27,178][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling finished in 
> 39 ms
> [2022-05-26 20:58:27,769][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling started 
> [2022-05-26 21:02:03,588][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling finished in 
> 215819 ms
> [2022-05-26 21:02:03,593][ERROR][main][root] Test failed 
> [test=DegradationReproducer#reproduce[useBinaryArrays = true], 
> duration=218641]
> java.lang.AssertionError: 
> Expected: a value less than <1000L>
>  but: <*215819L*> was greater than <1000L>
>   at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
>   at org.junit.Assert.assertThat(Assert.java:956)
>   at org.junit.Assert.assertThat(Assert.java:923)
>   at 
> org.apache.ignite.internal.binary.DegradationReproducer.reproduce(DegradationReproducer.java:27)
> {quote}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)


[jira] [Commented] (IGNITE-17043) Performance degradation in Marshaller

2022-05-30 Thread Ignite TC Bot (Jira)


[ 
https://issues.apache.org/jira/browse/IGNITE-17043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17543897#comment-17543897
 ] 

Ignite TC Bot commented on IGNITE-17043:


{panel:title=Branch: [pull/10045/head] Base: [master] : No blockers 
found!|borderStyle=dashed|borderColor=#ccc|titleBGColor=#D6F7C1}{panel}
{panel:title=Branch: [pull/10045/head] Base: [master] : New Tests 
(1)|borderStyle=dashed|borderColor=#ccc|titleBGColor=#D6F7C1}
{color:#8b}Basic 1{color} [[tests 
1|https://ci.ignite.apache.org/viewLog.html?buildId=6591916]]
* {color:#013220}IgniteBasicTestSuite: GridHandleTableSelfTest.testShrink - 
PASSED{color}

{panel}
[TeamCity *-- Run :: All* 
Results|https://ci.ignite.apache.org/viewLog.html?buildId=6594200buildTypeId=IgniteTests24Java8_RunAll]

> Performance degradation in Marshaller
> -
>
> Key: IGNITE-17043
> URL: https://issues.apache.org/jira/browse/IGNITE-17043
> Project: Ignite
>  Issue Type: Bug
>  Components: cache
>Affects Versions: 2.13, 2.14
>Reporter: Sergey Kosarev
>Assignee: Semyon Danilov
>Priority: Major
>  Time Spent: 3h
>  Remaining Estimate: 0h
>
> There is a problem in ignite-core code in GridHandleTable used inside 
> OptimizedMarshaller where the internal buffers grow in size and does not 
> shrink back.
> What problematic is in GridHandleTable? This is its reset() method that fills 
> arrays in memory. Done once, it's not a big deal. Done a million times for a 
> long buffer, it becomes really long and CPU-consuming.
> Here is simple reproducer (omitting imports for brevity):
> Marshalling of the same object at first takes about 50ms, and then after 
> degradation more than 100 seconds.
> {code:title=DegradationReproducer.java|borderStyle=solid}
> public class DegradationReproducer extends BinaryMarshallerSelfTest {
> @Test
> public void reproduce() throws Exception {
> List> obj = IntStream.range(0, 
> 10).mapToObj(Collections::singletonList).collect(Collectors.toList());
> for (int i = 0; i < 50; i++) {
> Assert.assertThat(measureMarshal(obj), Matchers.lessThan(1000L));
> }
> binaryMarshaller().marshal(
> Collections.singletonList(IntStream.range(0, 
> 1000_000).mapToObj(String::valueOf).collect(Collectors.toList()))
> );
> Assert.assertThat(measureMarshal(obj), Matchers.lessThan(1000L));
> }
> private long measureMarshal(List> obj) throws 
> IgniteCheckedException {
> info("marshalling started ");
> long millis = System.currentTimeMillis();
> binaryMarshaller().marshal(obj);
> millis = System.currentTimeMillis() - millis;
> info("marshalling finished in " + millis + " ms");
> return millis;
> }
> }
> {code}
> on my machine reslust is:
> {quote}
> .
> [2022-05-26 20:58:27,178][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling finished in 
> 39 ms
> [2022-05-26 20:58:27,769][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling started 
> [2022-05-26 21:02:03,588][INFO 
> ][test-runner-#1%binary.DegradationReproducer%][root] marshalling finished in 
> 215819 ms
> [2022-05-26 21:02:03,593][ERROR][main][root] Test failed 
> [test=DegradationReproducer#reproduce[useBinaryArrays = true], 
> duration=218641]
> java.lang.AssertionError: 
> Expected: a value less than <1000L>
>  but: <*215819L*> was greater than <1000L>
>   at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
>   at org.junit.Assert.assertThat(Assert.java:956)
>   at org.junit.Assert.assertThat(Assert.java:923)
>   at 
> org.apache.ignite.internal.binary.DegradationReproducer.reproduce(DegradationReproducer.java:27)
> {quote}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)


[jira] [Commented] (IGNITE-17043) Performance degradation in Marshaller

2022-05-30 Thread Semyon Danilov (Jira)


[ 
https://issues.apache.org/jira/browse/IGNITE-17043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17543868#comment-17543868
 ] 

Semyon Danilov commented on IGNITE-17043:
-

A little benchmark for fill vs. unsafe implementation of GridHandleTable shows 
that there is no any reason to use unsafe instead of fill. That's why 
spineEmpty and nextEmpty arrays were removed.

JmhGridHandleTableBenchmark.safethrpt5  6,941 ± 0,949  ops/s
JmhGridHandleTableBenchmark.unsafe  thrpt5  6,495 ± 2,140  ops/s


{code:java}
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.ignite.internal.benchmarks.jmh.misc;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import 
org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl;
import org.apache.ignite.internal.util.GridHandleTable;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

/**
 * Benchmarks {@link PartitionUpdateCounterTrackingImpl} class.
 */
@State(Scope.Benchmark)
@Fork(1)
@Threads(1)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 3, time = 5)
@Measurement(iterations = 5, time = 10)
public class JmhGridHandleTableBenchmark {
/** Buffer size to store testing gaps. */
private GridHandleTable table;

private List lst = new ArrayList<>();

/**
 * Setup.
 */
@Setup(Level.Iteration)
public void setupIteration() {
lst = IntStream.range(0, 
1_000_000).boxed().collect(Collectors.toList());
}

@Setup(Level.Invocation)
public void setupInvocation() {
table = new GridHandleTable(10, 3.00f);
}

/**
 * Update partition update counter with random gap.
 */
@Benchmark
public void unsafe() {
GridHandleTable.USE_UNSAFE = true;

put();
}

@Benchmark
public void safe() {
GridHandleTable.USE_UNSAFE = false;

put();
}

private void put() {
lst.forEach(table::putIfAbsent);

table.clear();
table.putIfAbsent(1337);
table.clear();
table.putIfAbsent(1337);
table.clear();
table.putIfAbsent(1337);
table.clear();
table.putIfAbsent(1337);
table.clear();
table.putIfAbsent(1337);
table.clear();
table.putIfAbsent(1337);
table.clear();
table.putIfAbsent(1337);
table.clear();
table.putIfAbsent(1337);
table.clear();
}

/**
 *
 * @param args Args.
 * @throws Exception Exception.
 */
public static void main(String[] args) throws Exception {
final Options options = new OptionsBuilder()
.include(JmhGridHandleTableBenchmark.class.getSimpleName())
.build();

new Runner(options).run();
}
}

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is