-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
325 additions
and
51 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
96 changes: 96 additions & 0 deletions
96
...rp/centraldogma/server/internal/storage/repository/git/GitRepositoryHistoryBenchmark.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,96 @@ | ||
/* | ||
* Copyright 2025 LINE Corporation | ||
* | ||
* LINE Corporation 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: | ||
* | ||
* https://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 com.linecorp.centraldogma.server.internal.storage.repository.git; | ||
|
||
import static com.linecorp.centraldogma.server.CentralDogmaBuilder.DEFAULT_REPOSITORY_CACHE_SPEC; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.util.concurrent.ForkJoinPool; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.TearDown; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import com.linecorp.armeria.common.metric.NoopMeterRegistry; | ||
import com.linecorp.centraldogma.common.Author; | ||
import com.linecorp.centraldogma.common.Change; | ||
import com.linecorp.centraldogma.common.Markup; | ||
import com.linecorp.centraldogma.common.Revision; | ||
import com.linecorp.centraldogma.internal.Util; | ||
import com.linecorp.centraldogma.server.internal.storage.repository.RepositoryCache; | ||
import com.linecorp.centraldogma.server.storage.project.Project; | ||
|
||
@State(Scope.Benchmark) | ||
public class GitRepositoryHistoryBenchmark { | ||
|
||
private static final Author AUTHOR = Author.ofEmail("[email protected]"); | ||
|
||
@Param({ "100", "1000"}) | ||
private int noCommits; | ||
|
||
@Param({ "1", "3", "5", "10", "30" }) | ||
private int noFiles; | ||
|
||
private File repoDir; | ||
private GitRepository repo; | ||
private int currentRevision; | ||
private RepositoryCache cache; | ||
|
||
@Setup | ||
public void init() throws Exception { | ||
repoDir = Files.createTempDirectory("jmh-gitrepository.").toFile(); | ||
cache = new RepositoryCache(DEFAULT_REPOSITORY_CACHE_SPEC, NoopMeterRegistry.get()); | ||
repo = new GitRepository(mock(Project.class), repoDir, ForkJoinPool.commonPool(), | ||
System.currentTimeMillis(), AUTHOR, | ||
cache); | ||
currentRevision = 1; | ||
|
||
// 1000 is the maximum number of allowed commits for a single history query. | ||
for (int i = 0; i < noCommits; i++) { | ||
addCommit(i); | ||
} | ||
} | ||
|
||
@TearDown | ||
public void destroy() throws Exception { | ||
repo.internalClose(); | ||
Util.deleteFileTree(repoDir); | ||
} | ||
|
||
@Benchmark | ||
public void history(Blackhole bh) throws Exception { | ||
cache.clear(); | ||
for (int i = 0; i < noFiles; i++) { | ||
bh.consume(repo.blockingHistory(new Revision(noCommits), Revision.INIT, | ||
"/dir/file_" + i + ".txt", 1)); | ||
} | ||
} | ||
|
||
private void addCommit(int index) { | ||
repo.commit(new Revision(currentRevision), currentRevision * 1000L, AUTHOR, | ||
"Summary", "Detail", Markup.PLAINTEXT, | ||
Change.ofTextUpsert("/dir/file_" + index + ".txt", | ||
String.valueOf(currentRevision))).join(); | ||
currentRevision++; | ||
} | ||
} |
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
...necorp/centraldogma/server/internal/storage/repository/git/CacheableObjectLoaderCall.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 2025 LINE Corporation | ||
* | ||
* LINE Corporation 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: | ||
* | ||
* https://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 com.linecorp.centraldogma.server.internal.storage.repository.git; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.jgit.lib.AnyObjectId; | ||
import org.eclipse.jgit.lib.ObjectLoader; | ||
|
||
import com.google.common.base.MoreObjects.ToStringHelper; | ||
import com.google.common.primitives.Ints; | ||
|
||
import com.linecorp.centraldogma.server.internal.storage.repository.CacheableCall; | ||
import com.linecorp.centraldogma.server.storage.repository.Repository; | ||
|
||
final class CacheableObjectLoaderCall extends CacheableCall<ObjectLoader> { | ||
|
||
private final AnyObjectId objectId; | ||
private final int hashCode; | ||
|
||
CacheableObjectLoaderCall(Repository repo, AnyObjectId objectId) { | ||
super(repo); | ||
this.objectId = objectId; | ||
hashCode = objectId.hashCode() * 31 + System.identityHashCode(repo); | ||
} | ||
|
||
@Override | ||
protected int weigh(ObjectLoader value) { | ||
return Ints.saturatedCast(value.getSize()); | ||
} | ||
|
||
/** | ||
* Never invoked because {@link GitRepository} produces the value of this call. | ||
*/ | ||
@Override | ||
public CompletableFuture<ObjectLoader> execute() { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
|
||
final CacheableObjectLoaderCall that = (CacheableObjectLoaderCall) o; | ||
return objectId.equals(that.objectId); | ||
} | ||
|
||
@Override | ||
protected void toString(ToStringHelper helper) { | ||
helper.add("objectId", objectId); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...linecorp/centraldogma/server/internal/storage/repository/git/CachingTreeObjectReader.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,74 @@ | ||
/* | ||
* Copyright 2025 LINE Corporation | ||
* | ||
* LINE Corporation 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: | ||
* | ||
* https://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 com.linecorp.centraldogma.server.internal.storage.repository.git; | ||
|
||
import static org.eclipse.jgit.lib.Constants.OBJ_TREE; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.eclipse.jgit.lib.AnyObjectId; | ||
import org.eclipse.jgit.lib.ObjectLoader; | ||
import org.eclipse.jgit.lib.ObjectReader; | ||
import org.eclipse.jgit.lib.ObjectReader.Filter; | ||
|
||
import com.linecorp.centraldogma.server.internal.storage.repository.RepositoryCache; | ||
import com.linecorp.centraldogma.server.storage.repository.Repository; | ||
|
||
final class CachingTreeObjectReader extends Filter { | ||
|
||
private final Repository repository; | ||
|
||
private final ObjectReader delegate; | ||
|
||
@Nullable | ||
private final RepositoryCache cache; | ||
|
||
CachingTreeObjectReader(Repository repository, ObjectReader delegate, @Nullable RepositoryCache cache) { | ||
this.repository = repository; | ||
this.delegate = delegate; | ||
this.cache = cache; | ||
} | ||
|
||
@Override | ||
protected ObjectReader delegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public ObjectLoader open(AnyObjectId objectId, int typeHint) | ||
throws IOException { | ||
// Only cache tree objects. | ||
if (OBJ_TREE != typeHint || cache == null) { | ||
return delegate.open(objectId, typeHint); | ||
} | ||
|
||
// Need to convert to objectId from MutableObjectId | ||
final AnyObjectId objectId0 = objectId.toObjectId(); | ||
|
||
final CacheableObjectLoaderCall key = new CacheableObjectLoaderCall(repository, objectId0); | ||
return cache.load(key, () -> { | ||
try { | ||
return delegate.open(objectId0, typeHint); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("failed to open an object: " + objectId0, e); | ||
} | ||
}, false); | ||
} | ||
} |
Oops, something went wrong.