# Persistent Media I/O in C#

> The eXtremeDB disk manager supports asynchronous I/O and different multi-file formats as described in the following sections.

> ## Asynchronous file I/O

> By default, AIO is disabled. In order to use the asynchronous I/O mode, the application sets the `DB_USE_AIO` bit in the `Database.Parameters.Mode` bitmask. The default parameters for AIO are `max_queue_length=10007` (the size of the asynchronous transaction buffer) and `n_workers=1` (the number of worker threads writing data to the persistent media.) If these parameters need to be altered the Database method `AioStart()` must be called after the Database constructor but before the Database method `Open()` . The `AioStart()` API signature is as follows:

>         public static void AioStart(long max_queue_length, long n_workers);

> And when closing the database, AIO processing should be closed explicitly by calling Database method `AioStop()`. For example:

>         Database db = new Database(Database.Mode.DiskSupport);
>         Database.Parameters params = new Database.Parameters();
>         Database.Device devs[];
>         ...
>         params.mode |= Database.DB_USE_AIO;
>         ...
>         db.AioStart(1000,2);
>         db.Open("opendb", params, devs);
>         ...
>         // Database processing

>         db.AioStop();

> By default, one AIO thread is started for each database and the default queue size is set to 10007. Sometimes it could be beneficial to change the number of AIO threads (for example if the database is comprised of multiple physical IO devices, or is resided on a RAID) and/or the queue size. However note that the number of I/O threads won't exceed the number of databases created in a process, regardless of the value of worker threads passed by the application (the runtime does not allow more than one AIO thread to serve a database)

> (Applications do not need to call either of these methods, `AioStart()` or `AioStop()`, if the default values are acceptable.)

> ## Multi-file databases

> Multi-file devices are defined in the same manner as other persistent memory devices except that they are of type `MultiFileDevice` or `RaidDevice`.

> For multifile implementations, segments can be added at runtime by means of Database method `Extend()`. Note that multifile segments cannot be removed.