TaskManager needs to be reworked

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
It's odd that i asked several times in the forum if somebody has set up the "Web Garden", and nobody answers.
Does that mean every body is using just one Worker Process? in the case the performance is horrible.

I have been using 3 worker processes since two weeks, it do help a lot for concurrent visits. The only issue I ran into so far is "Duplicate Emails"
https://www.nopcommerce.com/boards/t/19148/duplicate-emails.aspx?p=2

I digged into the code and find that problem is TaskManager. It is not thread safe/ inter Process safe.
All 3 worker processes are running the tasks, so sometimes customers got 3 duplicate emails.

I personally solved this problem in the TimerHandler, which check MUTEX and ensure no group of tasks run at the same time.
I'm happy to share with you guys who have the same problem.

  
private void TimerHandler(object state)
{
            //[JD] make exclusive access, do NOT run tasks simultaneously
            string appGuid = ((GuidAttribute) Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (GuidAttribute), false).GetValue(0)).Value;
            string mutexId = string.Format("Global\\{{{0}}}_{1}", appGuid, Seconds); //so that at least this group (grouped by seconds) won't run
          
            using (var mutex = new Mutex(false, mutexId))
            {
                var hasHandle = false;
                try
                {
                    try
                    {
                        hasHandle = mutex.WaitOne(1000, false);
                        if (hasHandle == false) return;
                    }
                    catch (AbandonedMutexException)
                    {
                        hasHandle = true;
                    }

                    #region do work

                    this._timer.Change(-1, -1);
                    this.Run();

                    if (this.RunOnlyOnce)
                        this.Dispose();
                    else
                        this._timer.Change(this.Interval, this.Interval);
                  

                    #endregion
                }
                finally
                {
                    if (hasHandle) mutex.ReleaseMutex();
                }
            }
        }



Yet still, I don't think it is an elegant solution.
The Code for TaskManger/Task/TaskThread are not really clean, need to be reworked.
Properties like "IsRunning" are useless.
Maybe Andrey could have some time clean the things up.
9 years ago
Hi,

You're aboslutely right. Web farms (and gardens) are not supported yet. When we start working on this task, it's better to support all configurations (web garden, web farm, azure, etc). This suggested solution supports only web gardens. Please find and vote for this work item here.
9 years ago
a.m. wrote:
Hi,

You're aboslutely right. Web farms (and gardens) are not supported yet. When we start working on this task, it's better to support all configurations (web garden, web farm, azure, etc). This suggested solution supports only web gardens. Please find and vote for this work item here.


Thanks, I did vote that months ago.
Hope it could get done soon.
Coz from my experiences, performance is unacceptable when active users are more than 20.
9 years ago
J.Ding, you have my vote too!

Have you any upgrade on this?

Ill start to try it.
9 years ago
ivanslater wrote:
J.Ding, you have my vote too!

Have you any upgrade on this?

Ill start to try it.


use my code above, it should work if you are using web garden
9 years ago
BTW, have you changed other codes to support gardens?
9 years ago
ivanslater wrote:
BTW, have you changed other codes to support gardens?

I did, many small optimization. but this one was the most disturbing problem.
9 years ago
Can you share it with us?

Im need to make same changes.
9 years ago
Hi.

Im using your code and started to get this error in event viewer, apparently only when Im not logged in server.

Is it Pool permisson problem? My pool is using ApplicationPoolIdentity.

Message: Access to the path 'Global\{22ef6580-286d-4be4-a503-7cd7023b0ea1}_300' is denied.


Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.UnauthorizedAccessException
Stack:
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.Threading.Mutex+MutexTryCodeHelper.MutexTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.Mutex.CreateMutexWithGuaranteedCleanup(Boolean, System.String, Boolean ByRef, SECURITY_ATTRIBUTES)
   at System.Threading.Mutex..ctor(Boolean, System.String, Boolean ByRef, System.Security.AccessControl.MutexSecurity)
   at System.Threading.Mutex..ctor(Boolean, System.String)
   at Nop.Services.Tasks.TaskThread.TimerHandler(System.Object)
   at System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()
8 years ago
is there any news on this topic. i don't have a multi-shop solution but my clients receive order emails between 1 and 6 times. there are better and worse days and i have no idea where even to start to fix this. please help!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.