Sobes.tech

What enabled the increase in the replication service throughput from about 300 to 700 messages per second? How were ConcurrentDictionary and SemaphoreSlim used?

126

Task: Events are received from users, each needs to be verified in an external source, but it does not respond immediately. Implement VerificationService which: - Accepts events from users - Tries to verify each by contacting an external service - If the response is PENDING, retries sending this event no earlier than 5 seconds later - Maximum 3 attempts, after which the event ID is output to stdout with status FAILED - Successfully processed events are output to stdout with status VERIFIED The templates and stubs of external dependencies are already implemented: 1. VerificationStatus 2. Event 3. VerificationResult 4. IExternalSource public enum VerificationStatus { OK, Pending, Error } public record Event(string Id, string Payload); public record VerificationResult(VerificationStatus Status, string? Message = null); public interface IExternalSource { VerificationResult Verify(string eventId); } public class VerificationService { private readonly IExternalSource _externalSource; private const int MaxAttempts = 3; private static readonly TimeSpan RetryDelay = TimeSpan.FromSeconds(5); public VerificationService(IExternalSource externalSource) { _externalSource = externalSource; } // TODO: implement }

63

List<Action> actions = new List<Action>(); for (var count = 0; count < 10; count++) { actions.Add(() => System.Console.WriteLine(count)); } foreach (var action in actions) { action(); } What will be in stdout?

60

public class A { public virtual void Print1() { System.Console.Write("A"); } public void Print2() { System.Console.Write("A"); } } public class B : A { public override void Print1() { System.Console.Write("B"); } } public class C : B { public new void Print2() { System.Console.Write("C"); } } static void Main(string[] args) { var c = new C(); A a = c; a.Print1(); a.Print2(); c.Print2(); } What will be in stdout?

48

public struct S : IDisposable { private bool dispose; public void Dispose() { dispose = true; } public bool GetDispose() { return dispose; } } What will be in stdout?

48