none
Put inside a WCF Rest web service a priority queue system to manage emergencies first and other request second. RRS feed

  • Question

  • Good afternoon,

      If possible I'd like some challenging discussion about an architectural choice I have to make to implement a solution.

    Context

      WCF Rest web service (the web service is done up and running).

    Question

      How to manage each entering request in order to process first those estimated as a priority requests and only secondly those who are not considered has a priority request?

    Suggestion

      I thought at first  implementing a priority queue following the design suggested by James McCaffrey.

     I thought implementing it using the singleton design making it able to be shared by all request whith a DB table to manage data linked with entering requests..

    Two problems

      1- The singleton in IIS will be reinitialized when the pool is reinitialized , and this can occurs automatically without control  by IIS.

      2- How to make thread safe the manipulation of the List<T> that will store the heap?

    The solution I propose

    Elements

    Use of a thread safe singleton to store the requests (List<T>).
    Use of Windows tasks to call periodically the web service.
    Use of a DB locked table to flag 

    How

       Case of urgent requests
       
          A request arrives and is detected has beign a urgent one, we add it on the list (and DB) and treat it immediately and provide a response in a synchroneous manner to the requestor. Before sending the response we remove it fomr the List<T> (no use of piggybacked system).
      
       Case of not urgent requests
       
          A request arrives and is detected has beign a not urgent one, we add it on the list (and DB) and provide a response in a synchroneous manner to the requestor indicating the request is in the queue.
      
       Case of treating the queue
       
          Periodically a windows task call the web service to treat the queue for a limited time (time that can be dynamically adjusted)
      
       Case of pool request retarted unexpetedly
       
          When the web service try to add a request to the List<T> (and DB) , if the list is empty the system reloads the List<T> from the DB.
      

    Kind regards.

    Claude





    • Edited by csi-bxl Tuesday, December 11, 2018 8:45 AM
    Monday, December 10, 2018 8:46 PM

All replies

  • Within my limited knowledge, I don't think I can answer your question completely. As far as I know, when running a singleton service, WCF is hosted in a self-managed mode, which is parasitic in the currently running applications, such as winform, WPF. The singleton service is terminated only when the host is shut down. For list<t> in concurrent mode, you can use System.Collections.Concurrent.dll to ensure thread safety.

    [TestMethod]
            public void TestMethod1()
            {
                List<int> intList = new List<int>();
                var result = Parallel.ForEach(Enumerable.Range(1, 10000), (val) =>
                {
                    intList.Add(val);
                });
                if (result.IsCompleted)
                {
                    Console.WriteLine("intList.Count():" + intList.Count);
                }
                Assert.AreNotEqual(10000, intList.Count);
            }
            [TestMethod]
            public void TestMethod2()
            {
                ConcurrentBag<int> intList = new ConcurrentBag<int>();
                var result = Parallel.ForEach(Enumerable.Range(1, 10000), (val) =>
                {
                    intList.Add(val);
                });
                if (result.IsCompleted)
                {
                    Console.WriteLine("intList.Count():" + intList.Count);
                }
                Assert.AreEqual(10000, intList.Count);
            }
    
    This is just my personal opinion, hope it is useful to you
    Best Regards
    Abraham


    Tuesday, December 11, 2018 10:20 AM
    Moderator
  • Hello Abraham,

       Thank you for the answer, I'll have to test your proposal.

    Kind regards.

    Claude

    Thursday, December 13, 2018 8:57 AM