-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Storage Engines - Transactions
-
None
-
8
By default whenever a session gets initialized, we allocate the transaction structure along with it. Currently the memory allocated for the transaction is as follows:
/* Allocate the WT_TXN structure, including a variable length array of snapshot information. */
WT_RET(__wt_calloc(session, 1,
sizeof(WT_TXN) + sizeof(txn->snapshot_data.snapshot[0]) * S2C(session)->session_array.size,
&session_ret->txn));
The transaction allocation includes the snapshot size. The snapshot size is calculated for the maximum number of sessions that are configured for the WiredTiger. In the case of MongoDB, the default value of session_max was configured to 33000. Due to this reason we allocate around 258K bytes of memory for every session transaction. We generally never reach that many sessions in the WiredTiger.
Improve this memory allocation logic to consider 128 sessions by default, and whenever in any scenario when the session_array.cnt is going beyond 128, double the value to 256 and so on. Also, to avoid a scenario where the txn allocation size and the snapshot size values differ, we can fail the transaction, and when this transaction replays again, we can allocate the proper snapshot array.