Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows import monitor to notice use of PageCache for caching
Caching for temporary importer data structures, that is. This allows user to become aware of the fact that an performance of an import can degrade heavily when that happens. Some amount of information is also provided as to why of/off-heap allocators couldn't be used.
- Loading branch information
Showing
14 changed files
with
294 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...l/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/PageCacheArrayFactoryMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.unsafe.impl.batchimport.cache; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import org.neo4j.io.pagecache.PageCache; | ||
|
||
import static java.lang.String.format; | ||
import static org.neo4j.helpers.Format.bytes; | ||
|
||
public class PageCacheArrayFactoryMonitor implements NumberArrayFactory.Monitor | ||
{ | ||
// This field is designed to allow multiple threads setting it concurrently, where one of those will win and either one is fine | ||
// because this monitor mostly revolves around highlighting the fact that the page cache number array is in use at all. | ||
private final AtomicReference<String> failedFactoriesDescription = new AtomicReference<>(); | ||
|
||
@Override | ||
public void allocationSuccessful( long memory, NumberArrayFactory successfulFactory, | ||
Iterable<NumberArrayFactory.AllocationFailure> attemptedAllocationFailures ) | ||
{ | ||
if ( successfulFactory instanceof PageCachedNumberArrayFactory ) | ||
{ | ||
StringBuilder builder = | ||
new StringBuilder( format( "Memory allocation of %s ended up in page cache, which may impact performance negatively", bytes( memory ) ) ); | ||
attemptedAllocationFailures.forEach( | ||
failure -> builder.append( format( "%n%s: %s", failure.getFactory().toString(), failure.getFailure().toString() ) ) ); | ||
failedFactoriesDescription.compareAndSet( null, builder.toString() ); | ||
} | ||
} | ||
|
||
/** | ||
* Called by user-facing progress monitor at arbitrary points to get information about whether or not there has been | ||
* one or more {@link NumberArrayFactory} allocations backed by the {@link PageCache}, this because it severely affects | ||
* performance. Calling this method clears the failure description, if any. | ||
* | ||
* @return if there have been {@link NumberArrayFactory} allocations backed by the {@link PageCache} since the last call to this method | ||
* then a description of why it was chosen is returned, otherwise {@code null}. | ||
*/ | ||
public String pageCacheAllocationOrNull() | ||
{ | ||
String failure = failedFactoriesDescription.get(); | ||
try | ||
{ | ||
return failure; | ||
} | ||
finally | ||
{ | ||
if ( failure != null ) | ||
{ | ||
failedFactoriesDescription.compareAndSet( failure, null ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.