Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

High CPU usage during SqliteCommand.ExecuteReader() on locked table #313

Closed
avolinsky opened this issue Dec 29, 2016 · 2 comments
Closed

Comments

@avolinsky
Copy link

100% CPU (on single core) usage while waiting for table to unlock during read.

Minimal repro steps

  1. Lock a table
  2. Run select command against locked table
  3. Observe CPU spike

i.e.

using (var connectionA = new SqliteConnection("Data Source=testdb;Mode=Memory;Cache=Shared")) {
				connectionA.Open();
				var cmd1 = connectionA.CreateCommand();
				cmd1.CommandText = "CREATE TABLE Person ( Name nvarchar(4000) )";
				cmd1.ExecuteNonQuery();

				using (var transactionA = connectionA.BeginTransaction(IsolationLevel.Serializable)) {
					cmd1.CommandText = "insert into Person values ( 'joe' )";
					cmd1.Transaction = transactionA;
					cmd1.ExecuteNonQuery();

					using (var connectionB = new SqliteConnection("Data Source=testdb;Mode=Memory;Cache=Shared")) {
						connectionB.Open();
						var cmd2 = connectionB.CreateCommand();
						cmd2.CommandText = "select * from  Person";
						cmd2.ExecuteReader(); //high CPU until timeout
					}
				}
			}

Expected result

Minimal CPU usage while waiting for table to unlock

Actual result

Waiting takes all available CPU cycles

Further technical details

Missing a sleep in this loop ?

@bricelam
Copy link
Contributor

bricelam commented Dec 30, 2016

For triage context, the reason we didn't put a sleep there (removed in #108) is because there is no Thread class on .NET Standard 1.3.

@bricelam
Copy link
Contributor

Will update with the move to .NET Standard 2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants