A better way to simulate @Today/@Now in a view without killing performance
Tags: Domino Performance
In Kevin Marshall's and my session BP208 Go Domino Go! Application Performance Engineering for IBM Lotus Domino Developers, I discussed why auto-indexed views with @Today or @Now in column or selection formulas take up lots of reindexing time. You usually don't notice the performance hit during development and testing with only 100 or so documents, but it absolutely kills performance of the entire server once such a view grows to thousands of documents.
Developers are tempted to use @Today (or @Now) in view formulas when they, for example, have to create a view that shows all documents created in the last 5 days...
SELECT @Adjust(CreatedDate; 0; 0; 5; 0; 0; 0) > @Today
One way around this I proposed in the session is to use a daily agent to move pertinent document into or out of a folder, which replaces the view. That works, but sometimes you really need the @Today / @Now for a column icon or more complex selection logic.
Public speaking rule #8: someone in the audience knows more than you.
An attendee at our session came up to me afterward and offered this nice suggestion... He said simply use the formula above, but hard-code today's date [01/30/2008] in place of @Today. Additionally, write a scheduled agent to change the view formula programmatically each night, so that the hard-coded date is updated each night. The view will reindex each night, but be fast throughout the next day's usage.
I had to share such a great idea. Everytime I present a session to a keen audience, I learn something new myself and this was no different. Wish I had gotten the name of who suggested it. Please let me know if it was you.
In Kevin Marshall's and my session BP208 Go Domino Go! Application Performance Engineering for IBM Lotus Domino Developers, I discussed why auto-indexed views with @Today or @Now in column or selection formulas take up lots of reindexing time. You usually don't notice the performance hit during development and testing with only 100 or so documents, but it absolutely kills performance of the entire server once such a view grows to thousands of documents.
Developers are tempted to use @Today (or @Now) in view formulas when they, for example, have to create a view that shows all documents created in the last 5 days...
SELECT @Adjust(CreatedDate; 0; 0; 5; 0; 0; 0) > @Today
One way around this I proposed in the session is to use a daily agent to move pertinent document into or out of a folder, which replaces the view. That works, but sometimes you really need the @Today / @Now for a column icon or more complex selection logic.
Public speaking rule #8: someone in the audience knows more than you.
An attendee at our session came up to me afterward and offered this nice suggestion... He said simply use the formula above, but hard-code today's date [01/30/2008] in place of @Today. Additionally, write a scheduled agent to change the view formula programmatically each night, so that the hard-coded date is updated each night. The view will reindex each night, but be fast throughout the next day's usage.
I had to share such a great idea. Everytime I present a session to a keen audience, I learn something new myself and this was no different. Wish I had gotten the name of who suggested it. Please let me know if it was you.
Comments
{ Link }
Posted by Ben Poole At 11:11:50 AM On 01/30/2008 | - Website - |
Will that work correctly? Or will it give a person viewing the doc the same user roles as the last person who caused the document to be computed?
My own testing has indicated that I need to make the field "Computed for display" to make this work.
Thoughts?
Posted by Timothy Briley At 01:31:59 PM On 01/30/2008 | - Website - |
Posted by Julian Woodward At 02:00:22 PM On 01/30/2008 | - Website - |
Posted by Jamie Magee At 02:15:22 PM On 01/30/2008 | - Website - |
"Note that @UserRoles is not necessarily recomputed at each occurence as of ND7."
Which means I shouldn't try to use this at all or ...?
Posted by Timothy Briley At 03:31:11 PM On 01/30/2008 | - Website - |
@5 - it's still good practice to write your logic in one place (CFD field) and reference it as often as needed. But my comment about ND7 is that consolidating such @UserRoles calls into once place is no longer a performance gain as far as I understand it. Lotus made Domino faster by caching @UserRoles called more than once on the same form.
Posted by Jamie Magee At 07:27:32 PM On 01/30/2008 | - Website - |
On a separate note, but the same presentation, you mentioned how expensive db.GetView is if you use aliases. Well everybody I talk to was pretty stunned by this because we all use aliases due to the business owners always wanting to change view names. Obviously I can avoid this by never using public views for lookups, but that requires duplicating views and that cure appears worse that the disease in terms of overall server performance.
Any idea if there has every been talk of adding "db.GetViewByAlias" or a server setting to first search for the view by alias, then by view name? Or is there a better way?
Posted by Timothy Briley At 11:11:04 PM On 01/30/2008 | - Website - |
Welcome to the Blogging world !
Coatsie
Posted by Coatsie At 04:31:33 AM On 01/31/2008 | - Website - |
Posted by Jim Knight At 08:12:30 AM On 01/31/2008 | - Website - |
Posted by Jamie Magee At 08:55:49 AM On 01/31/2008 | - Website - |
I don't have hundreds of views in one db (you do mean in just one db right?) and I never write case-mismatched anything (too anal-retentive), so maybe it doesn't matter, but only profiling will tell.
But it does appear that Lotus is penalizing those who are using what would otherwise be best practice.
Since I always want to have my cake and eat it too, I'm tempted to propose a optional parameter for getview: db.GetView(string, [aliasfirst])
Posted by Timothy Briley At 01:38:00 PM On 01/31/2008 | - Website - |
{ Link }
Posted by Jamie Magee At 07:23:34 AM On 02/01/2008 | - Website - |
Posted by Richard Shergold At 08:12:07 AM On 02/01/2008 | - Website - |
Posted by Jamie Magee At 04:55:15 PM On 02/01/2008 | - Website - |
Posted by Charles Robinson At 05:50:25 PM On 02/03/2008 | - Website - |
Posted by Patrick Kwinten At 04:03:56 AM On 02/06/2008 | - Website - |
In this case, Sean Burgess posted code { Link } last year that does exactly what you describe here using a hard-coded date and scheduled agent. This is something I picked up on { Link }
with the goal of making an "improvement" to the approach that was designed to handle different international date formats, only to be informed by Andre Guirard that it was unnecessary.
I liked this approach so much I incorporated it into SuperNTF. I'll probably now have to implement Charles suggestion to enable that agent in the template.
All goes to show great minds DO think alike
Posted by Kevin Pettitt At 09:21:45 AM On 02/07/2008 | - Website - |
@17 Pettitt - you are so right. I'm still catching up on good stuff from a year ago. thanks for the comments.
Posted by Jamie Magee At 10:30:05 AM On 02/08/2008 | - Website - |