Best way to unleash (for parallel processing) a web application without immediate processes?

I am looking for a good strategy to truly separate, for parallel processing, my web application (ASP.NET MVC / C #) instant processes. I define immediate as everything that is not required to be done right away to display a page or update information.

These processes include sending email, updating some internal statistics based on database information, fetching external information from web services, which should only be done periodically, etc.

Some communication must exist between the main ASP.NET MVC application and those background tasks; for example, an MVC application must report the process of sending email in order to send something.

What is the best strategy for this? MSMQ? Include all of these immediate processes in Windows services? I present a truly untied scenario, but I don’t want the compromise to complicate troubleshooting / unit testing or to introduce a huge amount of code.

Thanks!

+3
source share
10 answers

ThreadPool in .NET is a queue-based workgroup pool, however it is used by ASP.NET internal hosting, so if you try to use ThreadPool more, you can slow down the performance of the web server.

So, you have to create your own thread, mark it as background and give it a poll every few seconds for the availability of work.

: :

Table: JobQueue
JobID (bigint, auto number)
JobType (sendemail,calcstats)
JobParams (text)
IsRunning (true/false)
IsOver (true/false)
LastError (text)

JobThread .

class JobThread{
    static Thread bgThread = null;
    static AutoResetEvent arWait = new AutoResetEvent(false);

    public static void ProcessQueue(Job job)
    {
         // insert job in database
         job.InsertInDB();

         // start queue if its not created or if its in wait
         if(bgThread==null){
              bgThread = new Thread(new ..(WorkerProcess));
              bgThread.IsBackground = true;
              bgThread.Start();
         }
         else{
              arWait.Set();
         }
    }

    private static void WorkerProcess(object state){
         while(true){
              Job job = GetAvailableJob( 
                        IsProcessing = false and IsOver = flase);
              if(job == null){
                   arWait.WaitOne(10*1000);// wait ten seconds.
                                           // to increase performance
                                           // increase wait time
                   continue;
              }
              job.IsRunning = true;
              job.UpdateDB();
              try{

              //
              //depending upon job type do something...
              }
              catch(Exception ex){
                   job.LastError = ex.ToString(); // important step
                   // this will update your error in JobTable
                   // for later investigation
                   job.UpdateDB();
              }
              job.IsRunning = false;
              job.IsOver = true;
              job.UpdateDB();
         }
    }
}

, ASP.NET , , , Bitmap, ASP.NET , Windows .

Windows, ​​ , ASP.NET Windows Service WCF Mutex.

MSMQ MSMQ , , . MSMQ, , MSMQ , , . . , Win32, .

+2

ASP.NET, Python, ... , , .

, . - , IPC ( HTTP) . - , . RESTful , :

# In frontend (sorry for Python, should be clear)
...
backend_do_request("http://loadbalancer:7124/ipc", my_job)
...

# In backend (psuedoPython)
while 1:
   job = wait_for_request()
   myqueue.append(job)
...
def workerthread():
   job = myqueue.pop()
   do_job(job)

: " 2025?" .

Windows, , . , , IPC, - , IPC . ; .

+3

async- ASP.NET - ThreadPool , . , , , ThreadPool . # 4.0 Stealing ThreadPool, MindTouch Dream, Stealing Threadpool ( ) 3.5.

+1

Nservicebus , , , , msmq. , , , .net .

+1

.NET 4 Framework, F # Parallel Computing (http://msdn.microsoft.com/en-us/library/dd460693(VS.100).aspx)

F # , , .

, , WCF -, , .

: - , , - , , , webserver .

Spring.NET , -, .

, - , - MVC, , MVC -.

, Spring.NET , - , , , Spring.NET .

0

API , , , .BeginInvoke .

0

, " ", Windows, .

-, , , , , .

, , , , WCF, , .NET .

API- , Quartz.NET, . , , , , . , , , .

, - , - - , . , , .

0

Windows, , ThreadPool, MSMQ, , . , - .

0

MSMQ - . - . , . ( MSMQ , ). 8-9 , , :) MSMQ ( COM) - , .NET .

0

. SRP ( ). , , . " ".

, , , . MSMQ - , (, 5 , 5 ).

backround- asp.net - . , () inetinfo. , - , . , (, Windows Service). WCF, Microsoft WS-Reliability MSMQ. , WCF Windows. -, .

Spring.NET. : 1) Spring.NET 2) Spring.NET , .

: 1: - /, . ( ..). , . 2: Windows - - ( , ). , - Windows. (MSMQ, DB, FILE) . 100 Windows , , . 3: WCF, IIS, - , (2), , Windows WCF, ASP.NET . " " ( asp.net ), , msmq.

0
source

Source: https://habr.com/ru/post/1717027/


All Articles