Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 119 lines (99 sloc) 3.118 kb
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
1 using System;
2 using System.Collections.Generic;
e41f5e2 @kellabyte
kellabyte authored
3 using System.Diagnostics;
4 using System.Threading.Tasks;
5 using FluentCassandra.Types;
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
6 using FluentCassandra.Connections;
7 using Apache.Cassandra;
e41f5e2 @kellabyte
kellabyte authored
8
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
9 namespace FluentCassandra.StressTest
e41f5e2 @kellabyte
kellabyte authored
10 {
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
11 internal class Program
12 {
13 private static int count = 10000;
14 private static int dataLength = 1024;
15 private static int threadCount = 8;
16 private static string keyspaceName = "Blog";
17 private static Server server = new Server("localhost");
18
19 private static void SendDebugToConsole()
20 {
21 // Disable Debug traces
22 Trace.Listeners.Clear();
23
24 // Disable Debug assert message boxes
25 using (DefaultTraceListener listener = new DefaultTraceListener())
26 {
27 listener.AssertUiEnabled = false;
28 Trace.Listeners.Add(listener);
29 }
30
31 // Restore Debug traces to NUnit's Console.Out tab.
32 Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
33 }
34
35 private static void SetupKeyspace()
36 {
3254baf @nberardi cleaned up session, context, and keyspace objects
nberardi authored
37 using (var db = new CassandraContext(keyspace: keyspaceName, server: server))
38 {
39 if (!db.KeyspaceExists(keyspaceName))
40 db.AddKeyspace(new KsDef {
41 Name = keyspaceName,
42 Replication_factor = 1,
43 Strategy_class = "org.apache.cassandra.locator.SimpleStrategy",
44 Cf_defs = new List<CfDef>()
45 });
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
46
3254baf @nberardi cleaned up session, context, and keyspace objects
nberardi authored
47 if (!db.Keyspace.ColumnFamilyExists("Posts"))
48 db.AddColumnFamily(new CfDef {
49 Name = "Posts",
50 Keyspace = keyspaceName,
51 Column_type = "Super",
52 Comparator_type = "UTF8Type",
53 Subcomparator_type = "UTF8Type",
54 Comment = "Used for blog posts."
55 });
56 }
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
57 }
58
59 private static void Main(string[] args)
60 {
61 SendDebugToConsole();
62 SetupKeyspace();
63
64 Task[] tasks = new Task[threadCount];
65
66 Stopwatch watch = new Stopwatch();
67 watch.Start();
68
69 for (int i = 0; i < threadCount; i++)
70 {
71 tasks[i] = Task.Factory.StartNew(DoWork);
72 }
73
74 Task.WaitAll(tasks);
75 watch.Stop();
76
77 double rate = (count * threadCount) / watch.Elapsed.TotalSeconds;
78 double throughput = rate * dataLength;
79 Console.WriteLine("Total Completed: " + watch.Elapsed + "\tRate: " + rate + "\tThroughput: " + throughput);
80 Console.ReadKey();
81 }
82
83 private static void DoWork()
84 {
85 using (var db = new CassandraContext(keyspace: keyspaceName, server: server))
86 {
87 Stopwatch watch = new Stopwatch();
88 watch.Start();
89
90 Random random = new Random();
91 byte[] data = new byte[dataLength];
92 random.NextBytes(data);
93 int errors = 0;
94
95 for (int i = 0; i < count; i++)
96 {
97 // Insert
98 Guid postId = Guid.NewGuid();
99 string titleName = i.ToString();
100
101 var family = db.GetColumnFamily<UTF8Type, UTF8Type>("Posts");
102
357030e @DerekLiang forget to check-in changes for previous update
DerekLiang authored
103 dynamic post = family.CreateRecord(postId);
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
104 dynamic details = post.CreateSuperColumn();
105
106 details.Body = data;
107
f05f80c @DerekLiang Fixed an error that caused the StressTest Program didn't create any reco...
DerekLiang authored
108 post[DateTime.Now] = details;
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
109 db.Attach(post);
21aa083 @nberardi updated sandbox program to be broken up into logical parts
nberardi authored
110 db.SaveChanges();
d5455dc @nberardi updated server manager to have a more robust interface for handling bann...
nberardi authored
111 }
112
113 double rate = count / watch.Elapsed.TotalSeconds;
114 double throughput = rate * data.Length;
115 Console.WriteLine("Completed: " + watch.Elapsed + "\tRate: " + rate + "\tThroughput: " + throughput + "\tErrors:" + errors);
116 }
117 }
118 }
e41f5e2 @kellabyte
kellabyte authored
119 }
Something went wrong with that request. Please try again.