CqlPeerRepositoryPerformanceTests.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using Abc.Zebus.Directory.Cassandra.Cql;
  6. using Abc.Zebus.Directory.Cassandra.Storage;
  7. using Abc.Zebus.Directory.Cassandra.Tests.Cql;
  8. using Abc.Zebus.Routing;
  9. using Abc.Zebus.Testing.Extensions;
  10. using Abc.Zebus.Testing.Measurements;
  11. using NUnit.Framework;
  12. namespace Abc.Zebus.Directory.Cassandra.Tests.Storage
  13. {
  14. [TestFixture, Ignore("Performance tests")]
  15. public class CqlPeerRepositoryPerformanceTests : CqlTestFixture<DirectoryDataContext, ICassandraConfiguration>
  16. {
  17. protected override string Hosts
  18. {
  19. get { return "cassandra-test-host"; }
  20. }
  21. protected override string LocalDataCenter
  22. {
  23. get { return "Paris-CEN"; }
  24. }
  25. [Test]
  26. public void insert_30_peers_with_8000_subscriptions_each()
  27. {
  28. const int numberOfPeersToInsert = 30;
  29. var repo = new CqlPeerRepository(DataContext);
  30. var subscriptionForTypes = Get10MessageTypesWith800BindingKeysEach();
  31. for (var i = 0; i < numberOfPeersToInsert; i++)
  32. {
  33. var stopwatch = Stopwatch.StartNew();
  34. repo.AddOrUpdatePeer(new PeerDescriptor(new PeerId("Abc.Peer." + i), "tcp://toto:123", true, true, true, DateTime.UtcNow));
  35. repo.AddDynamicSubscriptionsForTypes(new PeerId("Abc.Peer." + i), DateTime.UtcNow, subscriptionForTypes);
  36. Console.WriteLine("Batch: " + i + " Elapsed: " + stopwatch.Elapsed);
  37. }
  38. var sw = Stopwatch.StartNew();
  39. var peers = repo.GetPeers().ToList();
  40. Console.WriteLine("GetPeers() took " + sw.Elapsed);
  41. peers.Count.ShouldEqual(30);
  42. foreach (var peer in peers)
  43. peer.Subscriptions.Length.ShouldEqual(8000);
  44. }
  45. [Test]
  46. public void insert_1_peer_with_100_000_subscriptions()
  47. {
  48. var repo = new CqlPeerRepository(DataContext);
  49. var subscriptionForTypes = Get1MessageTypesWith100000BindingKeys();
  50. var stopwatch = Stopwatch.StartNew();
  51. repo.AddOrUpdatePeer(new PeerDescriptor(new PeerId("Abc.Peer.0"), "tcp://toto:123", true, true, true, DateTime.UtcNow));
  52. repo.AddDynamicSubscriptionsForTypes(new PeerId("Abc.Peer.0"), DateTime.UtcNow, subscriptionForTypes);
  53. Console.WriteLine("Elapsed: " + stopwatch.Elapsed);
  54. Measure.Execution(20, () => repo.GetPeers(loadDynamicSubscriptions: false).ToList());
  55. var peers = repo.GetPeers(loadDynamicSubscriptions: false).ToList();
  56. peers.ExpectedSingle().Subscriptions.Length.ShouldEqual(0);
  57. }
  58. private SubscriptionsForType[] Get1MessageTypesWith100000BindingKeys()
  59. {
  60. var bindingKeys = Enumerable.Range(1, 100000).Select(i => new BindingKey(i.ToString())).ToArray();
  61. return new[] { new SubscriptionsForType(new MessageTypeId("Abc.Namespace.MessageType"), bindingKeys) };
  62. }
  63. private static SubscriptionsForType[] Get10MessageTypesWith800BindingKeysEach()
  64. {
  65. var messageTypes = Enumerable.Range(1, 10).Select(i => "Abc.Namespace.MessageType" + i).ToList();
  66. var subscriptionForTypes = new List<SubscriptionsForType>();
  67. foreach (var messageType in messageTypes)
  68. {
  69. var bindingKeys = Enumerable.Range(1, 800).Select(i => new BindingKey(i.ToString())).ToArray();
  70. subscriptionForTypes.Add(new SubscriptionsForType(new MessageTypeId(messageType), bindingKeys));
  71. }
  72. return subscriptionForTypes.ToArray();
  73. }
  74. // UselessKey
  75. // 100 iterations in 953 ms (105,0 iterations/sec)
  76. // Latencies :
  77. // Min : 6 068µs
  78. // Avg : 9 526µs
  79. // Median : 6 785µs
  80. // 95 percentile : 11 572µs
  81. // 99 percentile : 50 912µs
  82. // Max : 156 487µs (Iteration #0)
  83. // G0 : 18
  84. // G1 : 0
  85. // G2 : 0
  86. // Expected: 8000
  87. // But was: 0
  88. // Clean
  89. // 100 iterations in 1 242 ms (80,5 iterations/sec)
  90. // Latencies :
  91. // Min : 9 659µs
  92. // Avg : 12 416µs
  93. // Median : 10 291µs
  94. // 95 percentile : 12 751µs
  95. // 99 percentile : 65 848µs
  96. // Max : 109 858µs (Iteration #0)
  97. // G0 : 17
  98. // G1 : 0
  99. // G2 : 0
  100. // Expected: 8000
  101. // But was: 0
  102. }
  103. }