Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Optimization for minVV and maxVV calculation #1152

Closed
chacha912 opened this issue Feb 13, 2025 · 0 comments · Fixed by #1153 or #1164
Closed

Performance Optimization for minVV and maxVV calculation #1152

chacha912 opened this issue Feb 13, 2025 · 0 comments · Fixed by #1153 or #1164
Labels
enhancement 🌟 New feature or request

Comments

@chacha912
Copy link
Contributor

What would you like to be added:

Performance analysis of VV benchmark tests(#1150 ) revealed significant time and memory consumption in Version Vector Min/Max operations. This needs optimization to improve overall performance.

Current Performance Analysis

cpu-v057.prof mem-v057.prof
Image Image
  • CPU Profile
    • UpdateAndFindMinSyncedVersionVector: 20.48s (33.53%)
    • ApplyChanges: 9.83s (16.09%)
    • runtime.gcMarkWorker: 13.30s (21.81%)
  • Memory Profile
    • UpdateAndFindMinSyncedVersionVector > VersionVector Min: 29,524.84MB (58.10%)
    • ApplyChangePack > VersionVector Max: 14,841.02MB (29.20%)

1. MinVV Calculation (PushPull Operation)

  • Current implementation calculates minVV incrementally, using lots of memory
  • for _, vvi := range versionVectorInfos {
    if clientInfo.ID == vvi.ClientID {
    continue
    }
    if minVersionVector == nil {
    minVersionVector = vvi.VersionVector
    continue
    }
    minVersionVector = minVersionVector.Min(vvi.VersionVector)
    }
    if minVersionVector == nil {
    minVersionVector = versionVector
    }
    // 02-2. Compute min version vector with current client's version vector.
    minVersionVector = minVersionVector.Min(versionVector)

2. MaxVV Calculation (Attach Operation)

  • Used during SyncClocks when applying remote changes
  • Performance degrades with:
    • Increasing number of clients
    • Accumulating changes
  • Note: Current benchmark tests disable snapshots during attach

Steps to Reproduce

  1. Run benchmark with profiling:
go test -tags bench -benchmem -bench=BenchmarkVersionVector ./test/bench -memprofile=mem.prof -cpuprofile=cpu.prof
  1. Analyze profile:
# View single profile
go tool pprof [file path]
(pprof) web  # Requires graphviz package

# Compare two profiles
go tool pprof -base mem-v057.prof mem.prof
  • Profile data is available in the attached compressed files for reference. Test conducted with 1000 clients. prof.zip

Why is this needed:

To enhance performance during large-scale concurrent editing with multiple clients

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request
Projects
Status: Done
1 participant