public Client(Controllers.Reservation reservation, int id, int eventId, int delay, int checkDelay, int ticketsCount, int eventCapacity) { this.id = id; this.eventId = eventId; this.beforePlaceDelay = delay; this.checkDelay = checkDelay; this.ticketsCount = ticketsCount; this.reservationController = reservation; this.eventCapacity = eventCapacity; }
public Runner() { backend = new BackendSession(false); counterController = new Controllers.Tickets_Counter(backend); reservationController = new Controllers.Reservation(backend); eventController = new Controllers.Event(backend); CancellationTokenSource source = new CancellationTokenSource(); // Get one of the events to consider List <Models.Event> events = eventController.GetAllEvents(); Models.Event ev = events.Where(e => e.Id == 2).First(); Random rand = new Random(); // get initial tickets counter Console.WriteLine("Counter value: {0}", counterController.GetCurrentTicketsCount(ev.Id)); // run 5 rounds for (int k = 0; k < 5; k++) { // in 1150 threads List <Thread> threads = new List <Thread>(); for (int i = 0; i < 1000; i++) { var clientIdOffset_ = clientIdOffset; // run thread to place reservation and cancel 10% of them Thread t = new Thread(() => { Client c = new Client(reservationController, clientIdOffset_, ev.Id, 10, 5, 1, ev.Total_Tickets); c.run(); }); clientIdOffset += 1; t.Start(); threads.Add(t); } foreach (Thread th in threads) { th.Join(); } GetStatistics(ev.Id); } Thread.Sleep(1000); GetStatistics(ev.Id); }