Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fix for #88021 high GC pressure when driver configured with serversid… #25
Conversation
johnou
commented
Oct 8, 2017
•
|
Here is the benchmark code I used to verify increased throughput with the improved CompoundCacheKey (removed string concat from the constructor) vs the String key constructed with a StringBuilder. import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
/**
* @author Johno Crawford (johno.crawford@gmail.com)
*/
@State(Scope.Thread)
@Fork(5)
public class AllocationTest {
private String makePreparedStatementCacheKey(String catalog, String query) {
StringBuilder key = new StringBuilder();
key.append("/*").append(catalog).append("*/");
key.append(query);
return key.toString();
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void testCompoundCacheKeyNewHashCode() throws Exception {
new CompoundCacheKey("test", "select this_.id as id1_13_0_, this_.cost as cost2_13_0_, this_.local_currency as local_cu3_13_0_, this_.player_id as player_i4_13_0_, this_.receipt_data as receipt_5_13_0_, this_.retry_attempts as retry_at6_13_0_, this_.transaction_id as transact7_13_0_ from appstore_retry_queue this_");
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void testCompoundCacheKeyOldHashCode() throws Exception {
new CompoundCacheKeyOldHashCode("test", "select this_.id as id1_13_0_, this_.cost as cost2_13_0_, this_.local_currency as local_cu3_13_0_, this_.player_id as player_i4_13_0_, this_.receipt_data as receipt_5_13_0_, this_.retry_attempts as retry_at6_13_0_, this_.transaction_id as transact7_13_0_ from appstore_retry_queue this_");
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void testSimpleKey() throws Exception {
new SimpleKey("test", "select this_.id as id1_13_0_, this_.cost as cost2_13_0_, this_.local_currency as local_cu3_13_0_, this_.player_id as player_i4_13_0_, this_.receipt_data as receipt_5_13_0_, this_.retry_attempts as retry_at6_13_0_, this_.transaction_id as transact7_13_0_ from appstore_retry_queue this_");
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
public void testStringBuilder() throws Exception {
makePreparedStatementCacheKey("test", "select this_.id as id1_13_0_, this_.cost as cost2_13_0_, this_.local_currency as local_cu3_13_0_, this_.player_id as player_i4_13_0_, this_.receipt_data as receipt_5_13_0_, this_.retry_attempts as retry_at6_13_0_, this_.transaction_id as transact7_13_0_ from appstore_retry_queue this_");
}
static class CompoundCacheKeyOldHashCode {
String componentOne;
String componentTwo;
int hashCode;
CompoundCacheKeyOldHashCode(String partOne, String partTwo) {
this.componentOne = partOne;
this.componentTwo = partTwo;
// Handle first component (in most cases, currentCatalog being NULL....
this.hashCode = (((this.componentOne != null) ? this.componentOne : "") + this.componentTwo).hashCode();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof CompoundCacheKeyOldHashCode) {
CompoundCacheKeyOldHashCode another = (CompoundCacheKeyOldHashCode) obj;
boolean firstPartEqual = false;
if (this.componentOne == null) {
firstPartEqual = (another.componentOne == null);
} else {
firstPartEqual = this.componentOne.equals(another.componentOne);
}
return (firstPartEqual && this.componentTwo.equals(another.componentTwo));
}
return false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return this.hashCode;
}
}
static class CompoundCacheKey {
final String componentOne;
final String componentTwo;
final int hashCode;
CompoundCacheKey(String partOne, String partTwo) {
this.componentOne = partOne;
this.componentTwo = partTwo;
// Handle first component (in most cases, currentCatalog being NULL....
this.hashCode = 31 * (componentOne != null ? componentOne.hashCode() : 0) + (componentTwo != null ? componentTwo.hashCode() : 0);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof CompoundCacheKey) {
CompoundCacheKey another = (CompoundCacheKey) obj;
boolean firstPartEqual = false;
if (this.componentOne == null) {
firstPartEqual = (another.componentOne == null);
} else {
firstPartEqual = this.componentOne.equals(another.componentOne);
}
return (firstPartEqual && this.componentTwo.equals(another.componentTwo));
}
return false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return this.hashCode;
}
}
private final class SimpleKey {
private final String catalog;
private final String query;
public SimpleKey(String catalog, String query) {
this.catalog = catalog;
this.query = query;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SimpleKey simpleKey = (SimpleKey) o;
if (catalog != null ? !catalog.equals(simpleKey.catalog) : simpleKey.catalog != null) return false;
return query != null ? query.equals(simpleKey.query) : simpleKey.query == null;
}
@Override
public int hashCode() {
int result = catalog != null ? catalog.hashCode() : 0;
result = 31 * result + (query != null ? query.hashCode() : 0);
return result;
}
}
}
|
mysql-oca-bot
commented
Oct 8, 2017
|
Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at http://www.oracle.com/technetwork/community/oca-486395.html |
mysql-oca-bot
commented
Oct 10, 2017
|
Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment: |
johnou
commented
Oct 10, 2017
|
I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it. |
mysql-oca-bot
commented
Oct 10, 2017
|
Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow |
johnou commentedOct 7, 2017
…eprepared statements.
While profiling our application I found high GC pressure coming from the mysql driver [1]. The issue arises when the driver is configured to use serverside prepared statements and the driver recreates the cache key for every query (sb.toString() invoking Arrays.copyOfRange) [2].
[1]
[2]