Last active
August 29, 2015 14:22
-
-
Save martinesmann/2b3ee8e542e6c24862df to your computer and use it in GitHub Desktop.
Upsert to CB Server
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Couchbase; | |
using Couchbase.Configuration.Client; | |
namespace CouchbaseConnect2015 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Please wait... loading data..."); | |
UpsertTest(); | |
Console.ReadLine(); | |
} | |
private static ClientConfiguration GetConfig() | |
{ | |
return new ClientConfiguration | |
{ | |
Servers = new List<Uri> | |
{ | |
new Uri("http://192.168.1.11:8091/pools"), | |
}, | |
UseSsl = false, | |
BucketConfigs = new Dictionary<string, BucketConfiguration> | |
{ | |
{ | |
"default", | |
new BucketConfiguration | |
{ | |
BucketName = "default", | |
UseSsl = false, | |
Password = "", | |
PoolConfiguration = new PoolConfiguration | |
{ | |
MaxSize = 2, | |
MinSize = 1 | |
} | |
} | |
} | |
} | |
}; | |
} | |
private async static Task UpsertTest() | |
{ | |
Couchbase.ClusterHelper.Initialize(GetConfig()); | |
var bucket = Couchbase.ClusterHelper.GetBucket("default"); | |
Parallel.ForEach( | |
Enumerable.Range(0, 6 * 100000 /*6K runs*/).Select(i => Guid.NewGuid().ToString()), | |
async id => | |
{ | |
var start = DateTime.Now.Ticks; | |
int count = 0; | |
IOperationResult<dynamic> result = null; | |
string data = "Data"; | |
do | |
{ | |
result = await bucket.UpsertAsync<dynamic>(id, | |
new Document<dynamic> | |
{ | |
Id = id, | |
Content = new | |
{ | |
type = "Test", | |
value = data | |
} | |
}); | |
if (result.Status == Couchbase.IO.ResponseStatus.Success) | |
{ | |
//Console.Write("+"); | |
} | |
else | |
{ | |
count++; | |
//Console.Write("{0} ", count); | |
} | |
} | |
while (result == null || result.Status != Couchbase.IO.ResponseStatus.Success); | |
}); | |
Console.WriteLine("Data loaded"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment