public void epsilon_greedy_host_pool_alive() { var r = RethinkDB.R; var c = r.ConnectionPool() .Seed(new[] { "192.168.0.11:28015" }) .PoolingStrategy(new EpsilonGreedyHostPool(null, EpsilonCalculator.Linear())) .Discover(true) .Connect(); Thread.Sleep(10000); int result = r.random(1, 9).add(r.random(1, 9)).Run <int>(c); result.Should().BeGreaterOrEqualTo(2).And.BeLessThan(18); }
public void epsilon_test() { var sw = Stopwatch.StartNew(); EpsilonGreedyHostPool.Random = new Random(10); var p = new EpsilonGreedyHostPool(null, EpsilonCalculator.Linear(), autoStartDecayTimer: false); p.AddHost("a", null); p.AddHost("b", null); //initially hosts are not dead, for testing of course. foreach (var h in p.HostList) { h.Dead = false; } //Initially, A is faster than B; var timings = new Dictionary <string, long>() { { "a", 200 }, { "b", 300 } }; var hitCounts = new Dictionary <string, long>() { { "a", 0 }, { "b", 0 } }; var iterations = 12000; for (var i = 0; i < iterations; i++) { if ((i != 0) && (i % 100) == 0) { p.PerformEpsilonGreedyDecay(null); } var hostR = p.GetEpsilonGreedy();// as EpsilonHostPoolResponse; var host = hostR.Host; hitCounts[host]++; var timing = timings[host]; p.MarkSuccess(hostR, 0, TimeSpan.FromMilliseconds(timing).Ticks); } foreach (var host in hitCounts) { Console.WriteLine($"Host {host.Key} hit {host.Value} times {((double)host.Value / iterations):P}"); } // 60-40 //Host a hit 7134 times 59.45 % //Host b hit 4866 times 40.55 % hitCounts["a"].Should().BeGreaterThan(hitCounts["b"]); //hitCounts["a"].Should().Be(7134); //hitCounts["b"].Should().Be(4866); //=========================================== //timings change, now B is faster than A timings["a"] = 500; timings["b"] = 100; hitCounts["a"] = 0; hitCounts["b"] = 0; for (var i = 0; i < iterations; i++) { if ((i != 0) && (i % 100) == 0) { p.PerformEpsilonGreedyDecay(null); } var hostR = p.GetEpsilonGreedy();// as EpsilonHostPoolResponse; var host = hostR.Host; hitCounts[host]++; var timing = timings[host]; p.MarkSuccess(hostR, 0, TimeSpan.FromMilliseconds(timing).Ticks); } //TOTAL TIME: 177 milliseconds sw.Stop(); Console.WriteLine($"TOTAL TIME: {sw.Elapsed.Humanize()}"); foreach (var host in hitCounts) { Console.WriteLine($"Host {host.Key} hit {host.Value} times {((double)host.Value / iterations):P}"); } // 70-30 //Host a hit 3562 times 29.68 % //Host b hit 8438 times 70.32 % hitCounts["b"].Should().BeGreaterThan(hitCounts["a"]); //hitCounts["a"].Should().Be(3562); //hitCounts["b"].Should().Be(8438); }
private void Form1_Load(object sender, EventArgs e) { try { for (int i = 0; i < 10; i++) { //Stablish connection to RethinkDB Server that is running on Raspberry var conn = r.ConnectionPool().Seed(new[] { "192.168.0.184:28015", "192.168.1.202:28015", "192.168.1.189:28015" }); conn.PoolingStrategy(new EpsilonGreedyHostPool(new TimeSpan(0, 1, 0), EpsilonCalculator.Linear())).Discover(true); pool = conn.Connect(); Thread.Sleep(1000); } } catch (Exception ex) { MessageBox.Show("Impossible to Connect!"); } tb_mensagem.Text = ""; //Get all messages from RethinkDB List <Mensagem> all_messages = r.Db("chat").Table("chattable").OrderBy("Data").Run <List <Mensagem> >(pool); //Load all previous messages to the listbox of messages foreach (var message in all_messages) { //Create message Mensagem msg = new Mensagem(message.Id, message.Data, message.Username, message.Msg); //Adding Message to Listbox lb_chat.Items.Add(msg); } focus_last_message(); //Calling and running the task Task.Run(() => HandleUpdates(pool, lb_chat)); }
private void Login_Load(object sender, EventArgs e) { try { lb_alert.Text = "Trying to Reconnect..."; for (int i = 0; i < 10; i++) { var conn = r.ConnectionPool().Seed(new[] { "192.168.0.184:28015", "192.168.1.202:28015", "192.168.1.189:28015" }); conn.PoolingStrategy(new EpsilonGreedyHostPool(new TimeSpan(0, 1, 0), EpsilonCalculator.Linear())).Discover(true); pool = conn.Connect(); } } catch (Exception ex) { lb_alert.Text = "Impossible to Connect"; } }