Created
April 8, 2010 17:24
-
-
Save karlseguin/360305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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