# mco_trans_optimistic_threshold

> Control the MVCC Transaction Manager behavior with respect to the number of conflicts.

### Prototype

        void mco_trans_optimistic_threshold( /*IN*/ mco_db_h db,
                             /*IN*/ int max_conflicts_percent,
                             /*IN*/ int disable_period );

### Arguments

db | The database handle that was established by `mco_db_connect()`
max_conflicts_percent | The number of conflicts to process before switching to “exclusive mode”
disable_period | The number of `READ_WRITE` transactions to execute in “exclusive mode” after reaching the number of conflicts threshold

### Description

> This function helps optimization of MVCC performance. It controls the MVCC Transaction Manager behavior with respect to the number of conflicts (MVCC works best when the number of conflicts is small and poorly when there are many conflicts). The function sets two related parameters: `max_conflicts_percent` and `disable_period`. During the commit the MVCC Transaction Manager increments its internal “conflicts counter” (`n_conflicts`) if a conflict is detected and increments its internal successful "commit counter" (`n_commits`) otherwise. Furthermore, if the following condition holds:

>         n_conflicts/(n_conflicts + n_commits)*100 > max_conflicts_percent

> the subsequent `READ_WRITE` transactions up to the number specified in parameter `disable_period`, are executed in “exclusive mode” (only one `READ_WRITE` transaction at a time). Note that this does not affect `READ_ONLY` transactions—they are executed in parallel with `READ_WRITE` transactions and with other `READ_ONLY` transactions.

> By default this optimization is turned off, or in other words `max_conflicts_percent` = 100%.

### Return Codes

void | No return value

### Example

        Application snippet:

        const char * dbname = "SimpleDb";

        int main(int argc, char* argv[])
        {
            mco_db_h db;
            MCO_RET rc;
            mco_device_t       dev;
            mco_db_params_t    db_params;

            ...
            rc = mco_db_open_dev( dbname, simple_get_dictionary(), &dev, 1, &db_params );
            if ( MCO_S_OK != rc )
            {
                rc = mco_db_connect(  dbname, &db );
                ...
                mco_trans_optimistic_threshold( db, 10, 10);
                ...
            }
            ...
        }

### Files

Header file:
mco.h
Source file:
mursiw.c
Library:
libmcotexcl.a
Header file:
mco.h
Source file:
mursiw.c
Library:
libmcotmursiw.a
Header file:
mco.h
Source file:
mvcc.c
Library:
libmcotmvcc.a
Header file:
mco.h
Source file:
mursiw.c
Library:
libmcotread.a