Datei: StressTests/README.md

Last Commit (9de6a8c)
1 -- File didn't exist --
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
New Commit (bbf1d57)
1 # NDO Stress Test
2
3 Checks whether NDO handles many concurrent requests without errors. Many workers create, change, verify and
4 delete objects in parallel. They use only the async API of `PersistenceManager` and `VirtualTable<T>`.
5 Each worker creates its own `PersistenceManager` instance for every step.
6
7 ## Projects
8
9 | Project | Contents |
10 |---|---|
11 | `StressTestClasses` | Persistent classes `Customer`, `SalesOrder`, `OrderLine`, `Tag`. They are enhanced by the NDOEnhancer during the build, which also creates `NDOMapping.xml`. |
12 | `StressTest` | Console program that runs the test. References all providers. |
13
14 The relations cover the most important mapping variants:
15
16 * `SalesOrder.customer`: n:1, foreign key in `SalesOrder`
17 * `SalesOrder.lines` ↔ `OrderLine.order`: bidirectional 1:n composition, foreign key in `OrderLine`
18 * `SalesOrder.tags`: n:m via the mapping table `relSalesOrderTag`. The tags are created once and shared
19 ··by all workers.
20
21 ## Running the test
22
23 ```
24 cd StressTests/StressTest
25 dotnet run····································# Sqlite with the values from appsettings.json
26 dotnet run -- --provider Postgre --threads 100 --iterations 20
27 dotnet run -- -p SqlServer -t 200 -d 120······# 200 workers for 2 minutes
28 dotnet run -- -p MySql -c "Server=db;Database=ndostresstest;Uid=ndo;Pwd=secret"
29 dotnet run -- --help
30 ```
31
32 Supported providers: `Sqlite`, `SqlServer`, `MySql`, `MySqlConnector`, `Postgre`.
33
34 The connection strings are in the `ConnectionStrings` section of `appsettings.json`, one per provider.
35 So `--provider <name>` is all it takes to switch the provider. Local connection strings with passwords belong
36 in an `appsettings.local.json` next to `appsettings.json` (ignored by git) or in environment variables:
37
38 ```
39 export NDOSTRESS_ConnectionStrings__Postgre="Host=db;Database=ndostresstest;Username=ndo;Password=secret"
40 ```
41
42 Precedence: `appsettings.json` < `appsettings.local.json` < environment variables `NDOSTRESS_*` < command line.
43
44 The database must exist. The tables are dropped and recreated before the test (`--recreateSchema false`
45 turns this off). The DDL is created by the `ISqlGenerator` of the respective provider, just like the NDOEnhancer does.
46
47 Exit codes: 0 = success, 1 = errors, 2 = cancelled (Ctrl+C), 3 = configuration or setup error.
48 This makes the test usable in a script or a CI pipeline.
49
50 ## Steps of an iteration
51
52 Each worker runs its iterations one after another, each step with a new `PersistenceManager`:
53
54 1. **Create:** Create a customer and a sales order with lines and two tags (`FindObject`), `SaveAsync`.
55 2. **Read and change:** Load the order with `VirtualTable.SingleAsync`, `LoadRelationAsync`, `LoadDataAsync`;
56 ·· change the status, change, remove and add a line, replace a tag, change the customer, `SaveAsync`.
57 3. **Verify:** Check with `ToListAsync`, `CountAsync`, `SumAsync`, `FirstOrDefaultAsync`, `await foreach`
58 ·· (condition on a relation) and `RefreshAsync` that all changes have been saved.
59 4. **Query:** Queries over the data of all workers (`CountAsync`, `OrderByDescending`/`Take`).
60 5. **Delete:** Delete the order with `Delete` + `SaveAsync` (the composition deletes the lines and the
61 ·· mapping table entries), delete the customer with `DeleteDirectlyAsync`.
62 6. **Verify deletion:** Check that nothing is left.
63
64 Any deviation causes a `VerificationException`. After the run, the program compares the row counts of all
65 tables (including the mapping table) with the counts before the run. At the end it prints statistics of the
66 operations (count, average and maximum duration) and, if errors occurred, a grouping by step and exception type
67 as well as the first errors with stack traces.
68
69 ## Options
70
71 | Option | Default | Meaning |
72 |---|---|---|
73 | `--threads`, `-t` | 32 | Number of concurrent workers |
74 | `--iterations`, `-i` | 25 | Iterations per worker |
75 | `--duration`, `-d` | 0 | Run time in seconds instead of a fixed number of iterations |
76 | `--transactionMode` | Optimistic | `Optimistic` or `Pessimistic` |
77 | `--isolationLevel` | NDO default | e.g. `ReadCommitted`, `Serializable`. For Sqlite `Serializable` by default, see below |
78 | `--sharedMapping` | true | All PersistenceManagers share one `NDOMapping` object |
79 | `--lines`, `--tags` | 5, 8 | Lines per order, number of shared tags |
80 | `--recreateSchema` | true | Recreate the tables before the test |
81 | `--dropSchema` | false | Drop the tables after a successful test |
82 | `--stopOnFirstError` | false | Stop all workers at the first error |
83
84 ## Notes on the databases
85
86 * **Sqlite** allows only one writer at a time. A transaction that starts with a read
87 ··(`BEGIN DEFERRED`, corresponds to `ReadCommitted`) can't become a write transaction while another
88 ··connection is writing; Sqlite then reports `database is locked` immediately instead of waiting. Therefore the
89 ··test uses `Serializable` (`BEGIN IMMEDIATE`) for Sqlite by default. Use `--isolationLevel ReadCommitted` to see
90 ··the effect. The database file is created in the current directory.
91 * **Connection pools:** With many workers the maximum pool size must be large enough (500 in `appsettings.json`).
92 ··Otherwise there are timeouts when acquiring a connection, which have nothing to do with NDO.
93 * So far the test has only been run with Sqlite. For Postgre, the DDL shows that the provider's generator creates
94 ··the type `date` for `DateTime` and no primary key for identity columns. This doesn't matter for the test,
95 ··because it doesn't check times of day.
96