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

perf(core): update mongodb default connection settings #4646

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

dolcalmi
Copy link
Collaborator

@dolcalmi dolcalmi commented Nov 5, 2024

No description provided.

@github-actions github-actions bot added the core label Nov 5, 2024
@@ -29,9 +29,7 @@ const getWalletBalance = async (account: string, query = {}) => {

const balancePromise = (async () => {
try {
const { balance } = await MainBookAdmin.balance(params, {
readPreference: "secondaryPreferred",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

now it is not required because readPreference is setup at server level

{
account: liabilitiesWalletId,
},
{ readPreference: "primaryPreferred" },
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

now it is not required because readPreference default value is primaryPreferred

@dolcalmi dolcalmi requested a review from openoms November 5, 2024 23:59
Comment on lines +25 to +48
const DEFAULT_MONGODB_OPTIONS: mongoose.ConnectOptions = {
autoIndex: false,
compressors: ["snappy", "zlib"],

maxPoolSize: 100,
minPoolSize: 15,
maxConnecting: 5, // Maximum number of concurrent connection attempts

socketTimeoutMS: 60000, // Close sockets after 60 seconds of inactivity
connectTimeoutMS: 15000, // Give up initial connection after 15 seconds
serverSelectionTimeoutMS: 15000, // Keep trying to send operations for 15 seconds

retryWrites: true,
writeConcern: {
w: "majority", // Wait for majority acknowledgment
j: true, // Wait for journal commit
wtimeout: 10000, // Write timeout
},

retryReads: true,
maxStalenessSeconds: 90,
readPreference: "primaryPreferred", // Prefer primary but allow secondary reads
readConcern: { level: "majority" }, // Read from majority-committed data
} as const
Copy link
Collaborator

Choose a reason for hiding this comment

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

Compared the defaults there is compression introduced and more connections with bigger pool sizes, these settings expected to increase the performance.
Can you link the baseline you are comparing to?

Then in writeConcern and readConcern these settings should improve the consistency, hopefully not with too much tradeoff in performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants