Skip to content

Instantly share code, notes, and snippets.

@karlseguin
Created April 8, 2010 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlseguin/360305 to your computer and use it in GitHub Desktop.
Save karlseguin/360305 to your computer and use it in GitHub Desktop.
namespace MongoAuthTest
{
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Norm;
class Program
{
private static long _count;
private static readonly Random _random = new Random();
private static string[] _connections = new[]
{
"mongodb://admin:7c67ef13bbd4cae106d959320af3f704@localhost/NormTests",
"mongodb://other:91457513a48a1c160dbdebb19abe3e97@localhost/NormTests",
};
static void Main(string[] args)
{
var sw = new Stopwatch();
sw.Start();
for(var i = 0; i < 10; ++i)
{
new Thread(Process){IsBackground = true}.Start();
}
Console.ReadLine();
Console.ReadLine();
Console.ReadLine();
}
private static void Process()
{
while (true)
{
using (var mongo = Mongo.Create(_connections[_random.Next(0, _connections.Length)]))
{
var action = _random.Next(0, 5);
var collection = mongo.GetCollection<AuthTest>();
if (action == 0)
{
collection.Save(new AuthTest { Count = _random.Next(), Name = GetRandomString() });
}
else
{
collection.Count();
}
Interlocked.Increment(ref _count);
if (_count % 5000 == 0)
{
Console.WriteLine(_count);
}
}
}
}
private static string GetRandomString()
{
return Path.GetRandomFileName().Replace(".", "");
}
}
public class AuthTest
{
public ObjectId Id{ get; private set;}
public string Name{ get; set;}
public int Count{ get; set;}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment