Skip to content

Instantly share code, notes, and snippets.

@kellabyte
Created November 14, 2011 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kellabyte/1365485 to your computer and use it in GitHub Desktop.
Save kellabyte/1365485 to your computer and use it in GitHub Desktop.
Cassandra Performance Test
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using FluentCassandra;
using FluentCassandra.Types;
namespace CassandraTest1
{
class Program
{
private static int count = 10000;
private static int dataLength = 1024;
private static int threadCount = 8;
static void Main(string[] args)
{
Task[] tasks = new Task[threadCount];
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < threadCount; i++)
{
tasks[i] = Task.Factory.StartNew(DoWork);
}
Task.WaitAll(tasks);
watch.Stop();
double rate = (count * threadCount) / watch.Elapsed.TotalSeconds;
double throughput = rate * dataLength;
Console.WriteLine("Total Completed: " + watch.Elapsed + "\tRate: " + rate + "\tThroughput: " + throughput);
Console.ReadKey();
}
private static void DoWork()
{
using (var db = new CassandraContext("Blog", "localhost"))
{
Stopwatch watch = new Stopwatch();
watch.Start();
Random random = new Random();
byte[] data = new byte[dataLength];
random.NextBytes(data);
int errors = 0;
for (int i = 0; i < count; i++)
{
// Insert
Guid postId = Guid.NewGuid();
string titleName = i.ToString();
var family = db.GetColumnFamily<UTF8Type, UTF8Type>("Posts");
var post = family.CreateRecord(postId);
dynamic details = post.CreateSuperColumn();
details.Body = data;
db.Attach(post);
db.SaveChanges();
}
double rate = count / watch.Elapsed.TotalSeconds;
double throughput = rate * data.Length;
Console.WriteLine("Completed: " + watch.Elapsed + "\tRate: " + rate + "\tThroughput: " + throughput + "\tErrors:" + errors);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment