Question

I'm having the strangest issue... I have a monorail website (a .NET solution, similar to ASP.NET MVC).. and on one of the pages there is a save button. When the save button is clicked, it executes some code to save the object to the database, and then redirects to another page. However, what it does is immediately after you click the save button, it executes all of the save code, and then it sits there for a while, and then it redirects to the other page and executes its code. Here are some facts about the situation that make it especially strange.

  1. Every time you go through the process of clicking save and waiting for it to finish and redirect, it takes 2-4 seconds longer than the previous time you tried. So first time it'll take 2 seconds, then maybe 5, then 8, etc...
  2. If you recycle the app pool, it makes it run fast again, but then fact #1 kicks in and it gets slower the more times you do it.
  3. I added in logging and it executes the save and redirect code in 1 millisecond, then it waits for a while, and then it executes the new page's code quickly.
  4. I tried changing it to redirect to google.com and it still behaves this way.
  5. I tried making it not redirect at all, just serve up the existing page again after saving, and it still behaves this way.
  6. Every time you click save, it spikes the cpu (specifically the w3wp process.)
  7. Other pages do not behave this way, even other save methods.
  8. Commenting out the code that saves to the database makes it work correctly, with no wait.

So does anyone have any idea what would cause this? The save code uses Active Record and NHibernate. The code itself runs super fast, like I said it's less than 1ms, but it seems like there's something happening asynchronously AFTER the code finishes executing that makes it hang for a long time..

Any ideas would be greatly appreciated, the code is at http://pastebin.com/XGLAWPgK.

Was it helpful?

Solution

My Monorail is a bit rusty ...

Are you disposing of your ActiveRecord/nHibernate context after every request or caching it in the Session state? You shold create a new context for every request.

Are you Eager loading data entities? If you are Saving data, it may be fetching all associated entites.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top