Speed-up code that executes inside and outside critical sections
# Final Release Note Database code that executes inside and outside [critical sections](https://en.wikipedia.org/wiki/Critical_section) has been sped up, and critical section management has been significantly rewritten, as described in the blog post [Critical Section Performance in r2.04](https://yottadb.com/critical-section-performance-in-r2-04/). By default, YottaDB uses an adaptive mutex type with heuristic based switching between a YottaDB implementation and pthread_mutex operations provided by Linux. We recommend that you use the adaptive method unless you have a specific need to restrict critical section management, e.g., if you determine that a workload performs better with critical section management restricted to one or the other method. Even single process applications benefit from these optimizations. [#1178] ## Additional Information [MUPIP CREATE](https://docs.yottadb.com/AdminOpsGuide/dbmgmt.html#create) creates database files with critical section management initialized to use the adaptive method. You can use the [MUPIP SET](https://docs.yottadb.com/AdminOpsGuide/dbmgmt.html#set) command to restrict critical section management to use a specific method: ``` mupip set -mutex_type=ydb # restricts use to the built-in YottaDB method mupip set -mutex_type=pthread # restricts use to Linux pthread_mutexes mupip set -mutex_type=adaptive # reverts to switching between the two methods ``` The `-hard_spin_count` and `-soft_spin_counts` are meaningful only when the YottaDB method is in use for critical section management, either when explicitly specified, or chosen by the adaptive method heuristic. [DSE DUMP FILEHEADER](https://docs.yottadb.com/AdminOpsGuide/dse.html#f-ileheader) output includes a `Mutex Manager Type` field with the following values: - `ADAPTIVE (YDB)` - adaptive critical section management is active, and is currently using the YottaDB method. - `ADAPTIVE (PTHREAD)` - adaptive critical section management is active, and is currently using pthread_mutexes. - `YDB` - critical section management is restricted to use the YottaDB method. - `PTHREAD` - critical section management is restricted to use pthread_mutexes. [\$\$\%PEEKBYNAME()](https://docs.yottadb.com/ProgrammersGuide/utility.html#peekbyname) can also be used to access the current critical section management method. `$$^%PEEKBYNAME("mutex_struct.curr_mutex_type",<region>)` returns the following values corresponding to the `Mutex Manager Type` values reported by DSE DUMP FILEHEADER: - 0 for ADAPTIVE(YDB) - 1 for ADAPTIVE (PTHREAD) - 2 for YDB - 3 for PTHREAD The database statistics CQT and CYT reported by [ZSHOW "G"](https://docs.yottadb.com/ProgrammersGuide/commands.html#zshow) and [$VIEW("GVSTAT")](https://docs.yottadb.com/ProgrammersGuide/functions.html#view) are updated only when the YottaDB method is in use. # Description This Issue is a catch-all for performance improvements to database code that executes inside and outside critical sections. # Draft Release Note Database code that executes inside and outside [critical sections](https://en.wikipedia.org/wiki/Critical_section) has been sped up, and critical section management has been significantly rewritten, as described in the blog post [Critical Section Performance in r2.04](https://yottadb.com/critical-section-performance-in-r2-04/). By default, YottaDB uses an adaptive mutex type with heuristic based switching between a YottaDB implementation and pthread_mutex operations provided by Linux. We recommend that you use the adaptive method unless you have a specific need to restrict critical section management, e.g., if you determine that a workload performs better with critical section management restricted to one or the other method. Even single process applications benefit from these optimizations. [#1178] ## Additional Information [MUPIP CREATE](https://docs.yottadb.com/AdminOpsGuide/dbmgmt.html#create) creates database files with critical section management initialized to use the adaptive method. You can use the [MUPIP SET](https://docs.yottadb.com/AdminOpsGuide/dbmgmt.html#set) command to restrict critical section management to use a specific method: ``` mupip set -mutex_type=ydb # restricts use to the built-in YottaDB method mupip set -mutex_type=pthread # restricts use to Linux pthread_mutexes mupip set -mutex_type=adaptive # reverts to switching between the two methods ``` The `-hard_spin_count` and `-soft_spin_counts` are meaningful only when the YottaDB method is in use for critical section management, either when explicitly specified, or chosen by the adaptive method heuristic. [DSE DUMP FILEHEADER](https://docs.yottadb.com/AdminOpsGuide/dse.html#f-ileheader) output includes a `Mutex Manager Type` field with the following values: - `ADAPTIVE (YDB)` - adaptive critical section management is active, and is currently using the YottaDB method. - `ADAPTIVE (PTHREAD)` - adaptive critical section management is active, and is currently using pthread_mutexes. - `YDB` - critical section management is restricted to use the YottaDB method. - `PTHREAD` - critical section management is restricted to use pthread_mutexes. [\$\$\%PEEKBYNAME()](https://docs.yottadb.com/ProgrammersGuide/utility.html#peekbyname) can also be used to access the current critical section management method. `$$^%PEEKBYNAME("mutex_struct.curr_mutex_type",<region>)` returns the following values corresponding to the `Mutex Manager Type` values reported by DSE DUMP FILEHEADER: - 0 for ADAPTIVE(YDB) - 1 for ADAPTIVE (PTHREAD) - 2 for YDB - 3 for PTHREAD The database statistics CQT and CYT reported by [ZSHOW "G"](https://docs.yottadb.com/ProgrammersGuide/commands.html#zshow) and [$VIEW("GVSTAT")](https://docs.yottadb.com/ProgrammersGuide/functions.html#view) are updated only when the YottaDB method is in use.
issue