Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Phill 115 posts 288 karma points
    May 19, 2016 @ 05:08
    Phill
    0

    Umbraco ScheduledTasks Causing Delay with Custom PetaPoco Data Access

    Hi there,

    I'm not 100% sure my title is exactly what is happening but I'm pretty sure I've been able to narrow down my performance issue to something to do with the ScheduledTask running.

    Quick overview of my setup. I have an Umbraco 7.4.3 site running where I use the CMS for site structure and about 50% of the content. Then I have some Partial Views on page that use Ajax to call SurfaceControllers which then call my DataRepository classes which use PetaPoco and the ApplicationContext.Current.DatabaseContext.Database.

    Users are answering a series of questions (~250) using a simple YES/NO/NA dropdownlist and when that onchange fires I use ajax to call surface controller to save the response and check if there are any subsequent changes to questions. Running the SQL directly in MSSQLMS it's fast, and it's even fast running in Umbraco (40 - 80ms). This is great.

    The catch is that as you go through and answer questions one after another, every minute my call takes 8-15 seconds! It's almost as if the AppPool were restarting behind the scenes. However when I enable detailed logging and look at my log file I see the following right when my call starts and then my call doesn't finish until the ScheduledTasks complete. Scheduled tasks executing .... ... hits /ping.aspx ... Keep alive complete Scheduled publishing executing... Hits scheduledpublish/index .... Then my task completes.

    So I have a couple questions. I know I haven't posted any code and I can if required, but am I possibly doing something fundamentally wrong? Is there a way I can use PetaPoco and Umbraco DB Context on a different thread or something so the scheduled tasks don't hold things up? If that's not an option can I at least change the schedule for these tasks so that they run every 60 minutes and not 60 seconds. I can't seem to find this setting, as my UmbracoConfig file has nothing defined for scheduled tasks so I don't know what I would add to change this or if that's only for custom tasks and not these system tasks.

    Any insight would be greatly appreciated.

    Cheers, Phill

  • Phill 115 posts 288 karma points
    May 19, 2016 @ 12:54
    Phill
    0

    Just doing some more digging on this. Is it really possible that the background tasks KeepAlive, ScheduledPublishing, ScheduledTasks and LogScrubber are all hard coded to run every 60 seconds? As previously posted, the running of these tasks is making my apple unresponsive for 10-15 seconds, so I'm a little dumbfounded that I can't change the frequency without modifying source code for Umbraco. Please tell me I'm wrong:

    Umbraco-CMS/src/Umbraco.Web/Scheduling/Scheduler.cs RegisterBackgroundTasks I can't see anywhere else that these tasks are initialized and the timing is hard coded here.

    Again, any help is greatly appreciated. Phill

  • Phill 115 posts 288 karma points
    May 20, 2016 @ 14:17
    Phill
    0

    Still struggling with this so hoping someone might have someone from HQ with more intimate knowledge might be able to chime in. I've actually downloaded 7.4.3 source and changed the scheduled tasks in scheduler.cs to run every hour instead of every 60 seconds and I still have the issue. There is still something that runs even more frequently which could possibly be the issue. There's also the possibility that there are other things that aren't being logged with "debug" logging enabled.

    With scheduled tasks out of the picture, I still frequently get 10-15 second delays and they coincide with the following in the log: DEBUG Umbraco.Core.Sync.DatabaseServerMessenger - Syncing from database...

    With just a little digging I think this is for syncing in a multi-server environment? My site is running on single server (currently all local on single dev machine). Any ideas on how I could disable this to try and rule it out? Or where I can change the interval it runs at as it doesn't appear to be controlled by the Scheduler.

    Hoping someone can help out otherwise I'm going to have to scrap Umbraco completely, something I'm really hoping to avoid.

    Cheers, Phill

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    May 20, 2016 @ 14:53
    Nicholas Westby
    0

    I haven't seen that, but here are some links that might be of use:

    Based on what I read above, some things you might try:

    You might also use SQL Profiler to see what types of database operations are occurring every minute.

  • Phill 115 posts 288 karma points
    May 20, 2016 @ 22:32
    Phill
    0

    Hi Nicholas,

    Seems you're the only one here that ever responds to my posts, big thanks!!

    I will go through the above and check each to see if I can narrow it down. Right off the bat I don't actually have a "DistCache" folder under AppData. My project is built with NuGet and all is running locally. What or how would that folder and the lastsynced.txt file get created? I'm not at all familiar with this area but my wild guess is that it's something created for distributed servers/dbs and I'm running it all on the same box (local IIS though, not IIS Express, only use that when debugging). Network Service can create anything else under AppData so not sure why it wouldn't be able to create DistCache if needed.

    I also just have one row in umbracoCacheInstruction table, very little admin work on this site.

    A bit more info about the setup and what I've done so far. Am using a SurfaceController that inherits SurfaceRenderMvcController and function returns JsonResult. I don't think that it's an issue with DataAccess as monitoring using SQL profiler things run remarkably fast. I've tried moving things from SurfaceController to UmbracoApiController and same problem. The View is displaying the data using jQuery DataTables so I removed that from equation. After doing that, I don't think it's the "Syncing from database..." as I see that after almost every ajax call (not sure if that's normal or not). What I do see appear when it stalls for 10-15 seconds is the following: Umbraco.Web.Scheduling.BackgroundTaskRunner - [Umbraco.Web.Scheduling.IBackgroundTask] Task added Umbraco.Web.Strategies.ServerRegistrationEventHandler+TouchServerTask

    I no longer see any of the other scheduled tasks as I've hard coded them to only run every 60 minutes (but doesn't look like they were the problem).

    So I'm going to try and dig into source code to see what the ServerRegistrationEventHandler + TouchServerTask is/does and why it might be causing this issue. If you have any thoughts would love to hear them.

    Thanks again! Phill

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    May 20, 2016 @ 23:21
    Nicholas Westby
    0

    Oops, I think that file is actually located at ~/App_Data/TEMP/DistCache/SomeMachineName/SOMEID-lastsynced.txt.

    I believe that file indicates the ID of the row that was last synchronized to the current machine (e.g., for load balancing). I think this would exist on all machines, as flexible load balancing is now the default.

    So I'm going to try and dig into source code to see what the ServerRegistrationEventHandler + TouchServerTask is/does and why it might be causing this issue.

    Good luck! Maybe try disabling it temporarily to see if that helps anything. Perhaps by commenting out this class: https://github.com/umbraco/Umbraco-CMS/blob/75c2b07ad3a093b5b65b6ebd45697687c062f62a/src/Umbraco.Web/Strategies/ServerRegistrationEventHandler.cs

Please Sign in or register to post replies

Write your reply to:

Draft