Exemple #1
0
 public TransportMessage(MessageTypeId messageTypeId, byte[] messageBytes, OriginatorInfo originator, MessageId messageId)
 {
     Id = messageId;
     MessageTypeId = messageTypeId;
     MessageBytes = messageBytes;
     Originator = originator;
 }
            private void SetSubscriptionsForType(MessageTypeId messageTypeId, IEnumerable<BindingKey> bindingKeys, DateTime? timestampUtc)
            {
                var newBindingKeys = bindingKeys.ToHashSet();
                
                var messageTypeEntry = _peerSubscriptionsByMessageType.GetValueOrAdd(messageTypeId, MessageTypeEntry.Create);
                if (messageTypeEntry.TimestampUtc > timestampUtc)
                    return;

                messageTypeEntry.TimestampUtc = timestampUtc;

                foreach (var previousBindingKey in messageTypeEntry.BindingKeys.ToList())
                {
                    if (newBindingKeys.Remove(previousBindingKey))
                        continue;

                    messageTypeEntry.BindingKeys.Remove(previousBindingKey);

                    RemoveFromGlobalSubscriptionsIndex(messageTypeId, previousBindingKey);
                }

                foreach (var newBindingKey in newBindingKeys)
                {
                    if (!messageTypeEntry.BindingKeys.Add(newBindingKey))
                        continue;

                    AddToGlobalSubscriptionsIndex(messageTypeId, newBindingKey);
                }
            }
 public MessageExecutionCompleted(MessageId sourceCommandId, MessageTypeId payloadTypeId, byte[] payload)
 {
     SourceCommandId = sourceCommandId;
     ErrorCode = 0;
     PayloadTypeId = payloadTypeId;
     Payload = payload;
 }
Exemple #4
0
        public IMessage Deserialize(MessageTypeId messageTypeId, byte[] messageBytes)
        {
            var messageType = messageTypeId.GetMessageType();
            if (messageType == null)
                return null;

            return (IMessage)_serializer.Deserialize(messageType, new MemoryStream(messageBytes));
        }
        protected MessageHandlerInvoker(Type handlerType, Type messageType, bool? shouldBeSubscribedOnStartup = null)
        {
            MessageHandlerType = handlerType;
            DispatchQueueName = DispatchQueueNameScanner.GetQueueName(handlerType);
            MessageType = messageType;
            MessageTypeId = new MessageTypeId(MessageType);
            ShouldBeSubscribedOnStartup = shouldBeSubscribedOnStartup ?? MessageShouldBeSubscribedOnStartup(messageType);

            _instance = CreateConstructorInstance(handlerType);
        }
        public void MeasureUpdatePerformance()
        {
            var subscriptions = new List<Subscription>();
            for (var typeIdIndex = 0; typeIdIndex < 20; ++typeIdIndex)
            {
                var typeId = new MessageTypeId("Abc.Foo.Events.FakeEvent" + typeIdIndex);
                for (var routingIndex = 0; routingIndex < 500; ++routingIndex)
                {
                    subscriptions.Add(new Subscription(typeId, new BindingKey(routingIndex.ToString())));
                }
            }

            var subscriptionsByTypeId = subscriptions.GroupBy(x => x.MessageTypeId).ToDictionary(x => x.Key, x => x.Select(s=>s.BindingKey).ToArray());

            _directory = new PeerDirectoryClient(_configurationMock.Object);
            _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false)));

            Console.WriteLine("Snapshot updates (add)");
            using (Measure.Throughput(subscriptions.Count))
            {
                for (var subscriptionCount = 1; subscriptionCount <= subscriptions.Count; ++subscriptionCount)
                {
                    _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount))));
                }
            }
            Console.WriteLine("Snapshot updates (remove)");
            using (Measure.Throughput(subscriptions.Count))
            {
                for (var subscriptionCount = subscriptions.Count; subscriptionCount >= 1; --subscriptionCount)
                {
                    _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount))));
                }
            }

            _directory = new PeerDirectoryClient(_configurationMock.Object);
            _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false)));

            Console.WriteLine("Snapshot updates per message type id (add)");
            using (Measure.Throughput(subscriptions.Count))
            {
                foreach (var subscriptionGroup in subscriptionsByTypeId)
                {
                    _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key, subscriptionGroup.Value));
                }
            }
            Console.WriteLine("Snapshot updates per message type id (remove)");
            using (Measure.Throughput(subscriptions.Count))
            {
                foreach (var subscriptionGroup in subscriptionsByTypeId)
                {
                    _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key));
                }
            }
        }
        public void MeasureUpdatePerformanceWithManyBindingKeys()
        {
            var bindingKeys = new List<BindingKey>();
            var typeId = new MessageTypeId("Abc.Foo.Events.FakeEvent");
            for (var bindingKey = 0; bindingKey < 10000; ++bindingKey)
            {
                bindingKeys.Add(new BindingKey(bindingKey.ToString()));
            }
            var bindingKeysArray = bindingKeys.ToArray();

            _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false)));

            Measure.Execution(20, () =>
            {
                //_directory = new PeerDirectoryClient(_configurationMock.Object);
                //_directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false)));
                _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, typeId, bindingKeysArray));
                _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, typeId, new BindingKey[0]));
            });
        }
Exemple #8
0
 public TransportMessage CreateInfrastructureTransportMessage(MessageTypeId messageTypeId)
 {
     return(new TransportMessage(messageTypeId, new byte[0], PeerId, InboundEndPoint, MessageId.NextId()));
 }
Exemple #9
0
 public TransportMessage(MessageTypeId messageTypeId, byte[] messageBytes, PeerId senderId, string senderEndPoint, MessageId messageId)
     : this (messageTypeId, messageBytes, CreateOriginator(senderId, senderEndPoint), messageId)
 {
 }
        public void MeasureMemoryConsumption()
        {
            Console.WriteLine("Breakpoint here");

            for (var litePeerIndex = 0; litePeerIndex < 100; ++litePeerIndex)
            {
                var subscriptions = new List<Subscription>();
                for (var subscriptionIndex = 0; subscriptionIndex < 10; ++subscriptionIndex)
                {
                    subscriptions.Add(new Subscription(new MessageTypeId("Abc.Common.SharedEvent" + subscriptionIndex)));
                }

                for (var subscriptionIndex = 0; subscriptionIndex < 10; ++subscriptionIndex)
                {
                    subscriptions.Add(new Subscription(new MessageTypeId("Abc.Specific" + litePeerIndex + ".PrivateEvent" + subscriptionIndex)));
                }
                _directory.Handle(new PeerStarted(new PeerDescriptor(new PeerId("Abc.Testing.Peer" + litePeerIndex), "tcp://testing:11" + litePeerIndex, true, true, true, DateTime.UtcNow, subscriptions.ToArray())));
            }

            for (var fatPeerIndex = 0; fatPeerIndex < 30; ++fatPeerIndex)
            {
                var subscriptions = new List<Subscription>();
                for (var messageTypeIndex = 0; messageTypeIndex < 10; ++messageTypeIndex)
                {
                    var messageTypeId = new MessageTypeId("Abc.Common.SharedFatEvent" + messageTypeIndex);
                    for (var routingKeyIndex = 0; routingKeyIndex < 1000; ++routingKeyIndex)
                    {
                        subscriptions.Add(new Subscription(messageTypeId, new BindingKey(routingKeyIndex.ToString() + "00")));
                    }
                }
                _directory.Handle(new PeerStarted(new PeerDescriptor(new PeerId("Abc.Testing.FatPeer" + fatPeerIndex), "tcp://testing:22" + fatPeerIndex, true, true, true, DateTime.UtcNow, subscriptions.ToArray())));
            }

            Console.WriteLine("Breakpoint here");

            GC.Collect();

            Console.WriteLine("Breakpoint here");
        }
Exemple #11
0
 public TransportMessage CreateInfrastructureTransportMessage(MessageTypeId messageTypeId)
 {
     return(new TransportMessage(messageTypeId, new MemoryStream(), PeerId, InboundEndPoint));
 }
Exemple #12
0
        public static BindingKeyPart GetPartForMember(MessageTypeId messageTypeId, string memberName, BindingKey bindingKey)
        {
            var routingMember = GetRoutingMemberOrThrow(messageTypeId, memberName);

            return(bindingKey.GetPart(routingMember.Index));
        }
Exemple #13
0
 private ProtobufSurrogate(MessageTypeId typeId)
 => FullName = typeId.FullName;
        public void EnqueueMessage(PeerId peerId, MessageId messageId, MessageTypeId messageTypeId, byte[] bytes)
        {
            var entry = MatcherEntry.Message(peerId, messageId, messageTypeId, bytes);

            _persistenceQueue.Add(entry);
        }
 public void OnSendFailed(PeerId peerId, string endPoint, MessageTypeId messageTypeId, MessageId id)
 {
 }
Exemple #16
0
 public TransportMessage(MessageTypeId messageTypeId, byte[] messageBytes, PeerId senderId, string senderEndPoint, MessageId messageId)
     : this(messageTypeId, messageBytes, CreateOriginator(senderId, senderEndPoint), messageId)
 {
 }
Exemple #17
0
 public TransportMessage(MessageTypeId messageTypeId, byte[] messageBytes, Peer sender)
     : this(messageTypeId, messageBytes, sender.Id, sender.EndPoint, MessageId.NextId())
 {
 }
Exemple #18
0
 public static MatcherEntry Message(PeerId peerId, MessageId messageId, MessageTypeId messageTypeId, byte[] bytes)
 {
     return(new MatcherEntry(peerId, messageId, messageTypeId.FullName !, bytes, MatcherEntryType.Message, null));
 }
 private static IEnumerable <byte> GetHeaderBytes(MessageTypeId typeId)
 {
     return(FromUInt16((ushort)typeId).Concat(FromByte((byte)0)));
 }
 public void AddSerializationExceptionFor(MessageTypeId messageTypeId, string exceptionMessage = "Error")
 {
     _serializationExceptions.Add(messageTypeId, new Exception(exceptionMessage));
 }
Exemple #21
0
 public BasicMessage(MessageTypeId typeId)
 {
     TypeId = typeId;
 }
Exemple #22
0
 public MessageBinding(MessageTypeId messageTypeId, BindingKey routingKey)
 {
     MessageTypeId = messageTypeId;
     RoutingKey    = routingKey;
 }
Exemple #23
0
 public SubscriptionsForType(MessageTypeId messageTypeId, params BindingKey[] bindingKeys)
 {
     MessageTypeId = messageTypeId;
     BindingKeys   = bindingKeys;
 }
        public static IMessage ToMessage(this IMessageSerializer serializer, TransportMessage transportMessage, MessageTypeId messageTypeId, Stream content)
        {
            if (transportMessage.IsPersistTransportMessage)
            {
                return(ToPersistMessageCommand(transportMessage));
            }

            return(serializer.Deserialize(messageTypeId, content));
        }
Exemple #25
0
        public static IEnumerable <BindingKeyPart> GetPartsForMember(MessageTypeId messageTypeId, string memberName, IEnumerable <BindingKey> bindingKeys)
        {
            var routingMember = GetRoutingMemberOrThrow(messageTypeId, memberName);

            return(bindingKeys.Select(x => x.GetPart(routingMember.Index)));
        }
 public void RemoveDynamicSubscriptionsForTypes(PeerId peerId, DateTime timestampUtc, MessageTypeId[] messageTypeIds)
 {
     var peerEntry = GetEntry(peerId);
     if (peerEntry == null)
         return;
     if (timestampUtc >= peerEntry.PeerDescriptor.TimestampUtc)
         peerEntry.DynamicSubscriptions = peerEntry.DynamicSubscriptions.Where(sub => !messageTypeIds.Contains(sub.MessageTypeId)).ToList();
 }
        public void RemoveDynamicSubscriptionsForTypes(PeerId peerId, DateTime timestampUtc, MessageTypeId[] messageTypeIds)
        {
            if (messageTypeIds == null)
                return;
            var batch = _dataContext.Session.CreateBatch();
            batch.SetConsistencyLevel(ConsistencyLevel.LocalQuorum);

            foreach (var messageTypeId in messageTypeIds)
            {
                var deleteQuery = _dataContext.DynamicSubscriptions
                                              .Where(sub => sub.UselessKey == false && sub.PeerId == peerId.ToString() && sub.MessageTypeId == messageTypeId.FullName)
                                              .Delete()
                                              .SetTimestamp(timestampUtc);
                batch.Append(deleteQuery);
            }
            
            batch.Execute();
        }
            private void RemoveFromGlobalSubscriptionsIndex(MessageTypeId messageTypeId, BindingKey bindingKey)
            {
                var subscriptionTree = _globalSubscriptionsIndex.GetValueOrDefault(messageTypeId);
                if (subscriptionTree == null)
                    return;

                subscriptionTree.Remove(Peer, bindingKey);

                if (subscriptionTree.IsEmpty)
                    _globalSubscriptionsIndex.Remove(messageTypeId);
            }
 private void AddToGlobalSubscriptionsIndex(MessageTypeId messageTypeId, BindingKey bindingKey)
 {
     var subscriptionTree = _globalSubscriptionsIndex.GetOrAdd(messageTypeId, _ => new PeerSubscriptionTree());
     subscriptionTree.Add(Peer, bindingKey);
 }
 public PeerSubscriptionsForTypesUpdated(PeerId peerId, DateTime timestampUtc, MessageTypeId messageTypeId, params BindingKey[] bindingKeys)
 {
     PeerId = peerId;
     SubscriptionsForType = new [] { new SubscriptionsForType(messageTypeId, bindingKeys) };
     TimestampUtc = timestampUtc;
 }
Exemple #31
0
 public TransportMessage CreateInfrastructureTransportMessage(MessageTypeId messageTypeId)
 {
     throw new NotSupportedException();
 }
        public void MeasureMemoryConsumptionForSingleFatPeer()
        {
            var subscriptions = new List<Subscription>();
            for (var messageTypeIndex = 0; messageTypeIndex < 1; ++messageTypeIndex)
            {
                var messageTypeId = new MessageTypeId("Abc.Common.SharedFatEvent" + messageTypeIndex);
                for (var routingKeyIndex = 0; routingKeyIndex < 100000; ++routingKeyIndex)
                {
                    subscriptions.Add(new Subscription(messageTypeId, new BindingKey(routingKeyIndex.ToString() + "00")));
                }
            }

            Console.WriteLine("Breakpoint here");

            _directory.Handle(new PeerStarted(new PeerDescriptor(new PeerId("Abc.Testing.FatPeer0"), "tcp://testing:22", true, true, true, DateTime.UtcNow, subscriptions.ToArray())));

            Console.WriteLine("Breakpoint here");

            GC.Collect();

            Console.WriteLine("Breakpoint here");

            _directory.Handle(new PeerDecommissioned(new PeerId("Abc.Testing.FatPeer0")));

            Console.WriteLine("Breakpoint here");

            GC.Collect();

            Console.WriteLine("Breakpoint here");
        }
Exemple #33
0
 public TransportMessage CreateInfrastructureTransportMessage(MessageTypeId messageTypeId)
 {
     throw new NotSupportedException();
 }
Exemple #34
0
 public RequestMessage(MessageTypeId messageTypeId)
 {
     MessageId = (int)messageTypeId;
 }
Exemple #35
0
 public TransportMessage CreateInfrastructureTransportMessage(MessageTypeId messageTypeId)
 {
     return new TransportMessage(messageTypeId, new byte[0], PeerId, InboundEndPoint, MessageId.NextId());
 }
Exemple #36
0
 public TransportMessage(MessageTypeId messageTypeId, byte[] messageBytes, Peer sender)
     : this(messageTypeId, messageBytes, sender.Id, sender.EndPoint, MessageId.NextId())
 {
 }