// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; using Apache.Ignite.Core; using Apache.Ignite.Core.Client; using Apache.Ignite.Core.Client.Cache; using Apache.Ignite.Core.Cache.Query; namespace cache.IgniteSql.Performance { public class Program { private static void Put(ICacheClient cache, String key, int? value) { SqlFieldsQuery sfq = new SqlFieldsQuery("MERGE INTO performance_cache(ckey,cvalue) VALUES(?,?)"); sfq.Schema = "PUBLIC"; sfq.Arguments = new object[] { key, value }; cache.Query(sfq).GetAll(); } private const int N = 10000; private static void Test(ICacheClient cache) { // put speed DateTime dt1 = DateTime.Now; for(int i = 0; i < N; i++) { cache.Put("K#" + (i + 1), i + 1); } DateTime dt2 = DateTime.Now; Console.WriteLine("{0} puts per second", N * 1000 / (int)((dt2 - dt1).TotalMilliseconds)); } private const int REP = 5; public static void Main(string[] args) { IgniteClientConfiguration cfg = new IgniteClientConfiguration { Endpoints = new List { "localhost:10800" } }; using (IIgniteClient cli = Ignition.StartClient(cfg)) { ICacheClient cache = cli.GetOrCreateCache("performance_cache"); SqlFieldsQuery sfq = new SqlFieldsQuery("CREATE TABLE IF NOT EXISTS performance_cache (ckey VARCHAR(16) NOT NULL, cvalue INTEGER NOT NULL, PRIMARY KEY(ckey))"); sfq.Schema = "PUBLIC"; cache.Query(sfq).GetAll(); for(int i = 0; i < REP; i++) { Test(cache); } } } } }