Skip to content
Execute multiple concurrent requests asynchronously with Cassandra using the C# DataStax Driver
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
Program.cs
README.md
concurrent-requests-csharp.csproj

README.md

Concurrent Requests in C#

This example shows how execute multiple concurrent requests with Apache Cassandra™ using the C# DataStax Driver.

Contributors: João Reis - derived from here

Objectives

  • How to execute async concurrent requests while managing parallelism using the C# DataStax Driver

Project Layout

  • Program.cs - The main application file containing the logic for managing the number of simultaneous requests.

How this Works

This example creates a single tbl_sample_kv table in the examples keyspace and writes records to that table asynchronously while capping the max in-flight requests based on the configured concurrency level.

Setup and Running

Prerequisites

  • .NET Core 2.1
  • A Cassandra, DDAC, DSE database running ( docker is a nice option for local install - see docs )

If you do not currently have a C*/DDAC/DSE cluster available you can start a DDAC cluster using Docker via the following command:

docker run -e DS_LICENSE=accept --name ddac -p 127.0.0.1:9042:9042 -d datastax/ddac

If you have a DDAC/C*/DSE cluster but it is not located on localhost you need to change the contact point address located on line 33 to point to your cluster IP.

.AddContactPoint("XX.XX.XX.XX")

Running

From the root directory of this project, first run the following command to restore the dependencies:

dotnet restore

Once the restore has completed run the following command to build the application:

dotnet build

Finally to run the application use the following command:

dotnet run

When running you should see output similar to the following:

Executing 10000 queries with a concurrency level of 32, i.e., 32 tasks. Each task will process up to 313 operations.
Finished executing 10000 queries with a concurrency level of 32.```

You can’t perform that action at this time.