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

Reuse Large Buffers in MigrateSession #623

Merged
merged 44 commits into from
Sep 27, 2024

Conversation

vazois
Copy link
Contributor

@vazois vazois commented Aug 29, 2024

This PR tries to improve memory utilization and reduce fragmentation by reusing large buffers that were allocated across different migrate sessions.
The PR includes the following:

  • Introduce NetworkBufferSettings which is used to define the network buffer size configuration (i.e. send and receive buffer) for both clients and server implementation.
  • Augment the network stack to support user defined instances of LimitedFixedBufferPool (LBFP) and NetworkBufferSettings.
  • Define and use a shared instance of LFBP for ReplicationManager and MIgrationManager.
  • Introduce PURGEBP command to allow for user to purge the LBFP instances of ReplicationManager, MigrationManager and ServerListener.
  • Add BPSTATS section in INFO to retrieve stats about the declared LBFP instances of ReplicationManager, MigrationManager and ServerListener at runtime.

Notes:

  • There is an upper limit on the number of entries per level in the LimitedBufferPool which may cause fragmentation of the LOH due to the way we allocate and return buffers to the pool itself (shown below)
    if (Interlocked.Increment(ref pool[level].size) <= maxEntriesPerLevel)
    {
    Array.Clear(buffer.entry, 0, buffer.entry.Length);
    pool[level].items.Enqueue(buffer);
    }
    else
    Interlocked.Decrement(ref pool[level].size);
    The default limit is 16 entries which should be enough for common scenarios (i.e. up to 16 parallel migrate sessions and up to 16 replication sessions).

@vazois vazois force-pushed the vazois/migration-reuse-buffers branch 4 times, most recently from 29aa345 to 146da1a Compare September 4, 2024 20:26
@vazois vazois force-pushed the vazois/migration-reuse-buffers branch 3 times, most recently from e13374e to 9d65b87 Compare September 10, 2024 02:23
@vazois vazois marked this pull request as ready for review September 10, 2024 16:35
@vazois vazois marked this pull request as draft September 10, 2024 17:24
@vazois vazois force-pushed the vazois/migration-reuse-buffers branch 3 times, most recently from 18e9c50 to d34f522 Compare September 12, 2024 00:52
@vazois vazois marked this pull request as ready for review September 12, 2024 00:52
@vazois vazois force-pushed the vazois/migration-reuse-buffers branch 3 times, most recently from c362324 to dfc86d7 Compare September 18, 2024 17:10
Copy link
Contributor

@badrishc badrishc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

libs/cluster/Server/Failover/ReplicaFailoverSession.cs Outdated Show resolved Hide resolved
benchmark/Resp.benchmark/RespOnlineBench.cs Outdated Show resolved Hide resolved
libs/cluster/Server/Migration/MigrationManager.cs Outdated Show resolved Hide resolved
libs/cluster/Server/Replication/ReplicationManager.cs Outdated Show resolved Hide resolved
libs/common/Memory/LimitedFixedBufferPool.cs Show resolved Hide resolved
libs/common/Memory/LimitedFixedBufferPool.cs Show resolved Hide resolved
libs/common/NetworkBuffers.cs Outdated Show resolved Hide resolved
libs/server/Resp/PurgeBPCommand.cs Show resolved Hide resolved
libs/server/Resp/PurgeBPCommand.cs Show resolved Hide resolved
@vazois vazois force-pushed the vazois/migration-reuse-buffers branch 5 times, most recently from 8ce1809 to eceaa1e Compare September 20, 2024 18:37
@vazois vazois force-pushed the vazois/migration-reuse-buffers branch from 392194d to c6953af Compare September 26, 2024 22:01
@vazois vazois merged commit eb40cd9 into microsoft:main Sep 27, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants