Skip to content

Commit

Permalink
perf: handle leftover tickets async
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Aug 31, 2024
1 parent 9b47bca commit 4a46b50
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/main/java/com/ishland/flowsched/scheduler/ItemHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,30 @@ public void removeDependencyTicket(K key, ItemStatus<K, V, Ctx> status) {
}
}

public boolean isDependencyDirty() {
synchronized (this.dependencyInfos) {
return this.dependencyDirty;
}
}

public boolean holdsDependency() {
synchronized (this.dependencyInfos) {
for (ObjectBidirectionalIterator<Object2ReferenceMap.Entry<K, DependencyInfo>> iterator = this.dependencyInfos.object2ReferenceEntrySet().fastIterator(); iterator.hasNext(); ) {
final Object2ReferenceMap.Entry<K, DependencyInfo> entry = iterator.next();
final DependencyInfo info = entry.getValue();
int[] refCnt = info.refCnt;
for (int i : refCnt) {
if (i != -1) return true;
}
}
return false;
}
}

public void cleanupDependencies(StatusAdvancingScheduler<K, V, Ctx, ?> scheduler) {
synchronized (this.dependencyInfos) {
if (!dependencyDirty) return;
for (ObjectBidirectionalIterator<Object2ReferenceMap.Entry<K, DependencyInfo>> iterator = this.dependencyInfos.object2ReferenceEntrySet().iterator(); iterator.hasNext(); ) {
for (ObjectBidirectionalIterator<Object2ReferenceMap.Entry<K, DependencyInfo>> iterator = this.dependencyInfos.object2ReferenceEntrySet().fastIterator(); iterator.hasNext(); ) {
Object2ReferenceMap.Entry<K, DependencyInfo> entry = iterator.next();
final K key = entry.getKey();
final DependencyInfo info = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,20 @@ public boolean tick() {
}
if (nextStatus == current) {
if (current.equals(getUnloadedStatus())) {
holder.cleanupDependencies(this);
if (holder.isDependencyDirty()) { // schedule dependency cleanup async
holder.submitOp(CompletableFuture.runAsync(() -> {
holder.cleanupDependencies(this);
markDirty(holder.getKey());
}, getBackgroundExecutor()));
continue;
}
if (holder.holdsDependency()) {
if (holder.isDependencyDirty()) {
markDirty(holder.getKey()); // should rarely happen
continue;
}
System.err.println(String.format("BUG: %s still holds some dependencies when ready for unloading", holder.getKey()));
}
// System.out.println("Unloaded: " + key);
this.onItemRemoval(holder);
holder.release();
Expand Down

0 comments on commit 4a46b50

Please sign in to comment.