Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Perfomance, cache and expensive queries View modes: 
User avatar
Member
Member
Ark_IT - 2/24/2010 9:08:45 AM
   
Perfomance, cache and expensive queries
Hello!

Developed E-Shop with Kentico 4.1, 145000 skus, 3-level katalogue.
Perfomance - very poor. (It worked fine on LAMP before, everything was ok)

Added CMSDebugSQLQueriesLive - it shows always the same -

queries
(cms.document.selectuppertree) runs 1 time and (cms.document.selectdocuments) - 5 times on one page, and takes about 0.6 - 1.8 seconds each, so e.g. see 1 katalogue position takes 10 seconds!

made all of http://devnet.kentico.com/Forums.aspx?forumid=36&threadid=11972
cached pages works great - but theres >100.000 of them.

Is there any way to make cache before users come to site?
or something else with queries?

Xeon 3GHz 3Gb 64bit



User avatar
Member
Member
Ark_IT - 3/1/2010 2:23:31 AM
   
RE:Perfomance, cache and expensive queries
Solved this problem.
Changed queries cms.document.selectdocuments and cms.document.selectuppertree.
They originally uses WHERE condition with 'LIKE=' or '=', searching TEXT fields. It takes lot of time!

So i changed them, only in case they gets my catalogue info (datalist and breadcrumbs in catalogue).

Added BeforeExecuteQuery method and handler in BeforeAplicationStart method.
Now queries search with WHERE condition, containin 'NodeID = DocumentNodeID' and no text fields.
It work times faster! (for exmpl selectdocuments in breadcrumbs before takes 1.56 sec, now - 0.004 sec!)


Can u tell, is it good practice?
Why u use text search in such queries, when you already have nodeid and linknodeid, from first query (cms.tree.selectpageinfo)?

Thank you )


User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/8/2010 2:48:19 AM
   
RE:Perfomance, cache and expensive queries
Hello,

Could you please post examples of queries before and after the change? I am a bit confused of the changes you've made. I also consulted our developer and he think's this change may cause some issues.

Best regards,
Boris Pocatko

User avatar
Member
Member
Ark_IT - 3/9/2010 3:03:10 AM
   
RE:Perfomance, cache and expensive queries
Hello,

As i said - changes take only queries to my catalogue, wich consist branches like /Catalogue/n12345/n1245/n..... and each branch always end wit /tn_21212121....(somenumber) - i called it trade-name, it consist of several (1 or more) SKU.

Document "mydoc" (forexample)
Query - cms.document.selectdocuments (runs several times, i cannot change it in kentico webinterface)

important moments commented with //***

1. App_Code/Global/CMS/CMSApplication.cs
public static class CMSApplication
{
/// <summary>
/// Fires before the application start event
/// </summary>
public static void BeforeAplicationStart(object sender, EventArgs e)
{
// Add your custom actions
CMS.SettingsProvider.SqlHelperClass.OnBeforeExecuteQuery += new
CMS.SettingsProvider.SqlHelperClass.BeforeExecuteQueryEventHandler(BeforeExecuteQuery);
}

static void BeforeExecuteQuery(CMS.SettingsProvider.QueryParameters query, CMS.IDataConnectionLibrary.IDataConnection conn)
{

if (query.Name != null)
{

switch (query.Name.ToLower())
{

case "cms.document.selectdocuments":

//***if (query.Text.Contains("tn_")) - its a trade-name in catalogue

if ((query.Where.ToString().Contains("tn_")) && ((query.TopN == 1) || (query.TopN == 20)))
{
string idtradename = query.Where.Substring(query.Where.IndexOf("tn_") + 3, query.Where.IndexOf("'", query.Where.IndexOf("tn_") + 1, query.Where.Length - query.Where.IndexOf("tn_") - 1) - query.Where.IndexOf("tn_") - 3); //*** some handles witn string to get number after "tn_"
//*** change query to stored procedure!
query.Type = CMS.IDataConnectionLibrary.QueryTypeEnum.StoredProcedure;
query.Text = "Proc_CMS__tn_selectdocuments";

object[,] parameters = new object[1, 3];
parameters[0, 0] = "@idtradename";
parameters[0, 1] = idtradename;

query.Params = parameters;


}
else if (query.Where.ToString().Contains("/%'"))
{
//*** this query gets all the nodes UNDER current? so it always use LIKE and take lot of time
//*** so change it to search with nodeid - (!important) - nodeid is in branch name, number after "/n" - thats why i told this method is maybe for me only.
//*** its DocumentNamePath - and i use other, more userfriendly DocumentUrlPath for documents
string idnode = query.Where.Remove(query.Where.IndexOf("%") - 1).Substring(query.Where.LastIndexOf("/n") + 2);

query.Type = CMS.IDataConnectionLibrary.QueryTypeEnum.StoredProcedure;
query.Text = "Proc_CMS__tn_selectdocuments_prc";

object[,] parameters = new object[2, 3];
parameters[0, 0] = "@idnode";
parameters[0, 1] = idnode;
parameters[1, 0] = "@nodeclassid";
parameters[1, 1] = "2160";


query.Params = parameters;

}


break;
//*** maybe not to break and add the same to other cases

}

}
}
.............

2. Stored Procedures includes some searching in other databases and so on.
The main query is like this

SELECT View_CMS_Tree_Joined.*, MY_TradeName.* FROM View_CMS_Tree_Joined
INNER JOIN My_TradeName ON View_CMS_Tree_Joined.DocumentForeignKeyValue = My_TradeName.[TradeNameID] //*** foreinkey is tradename
WHERE nodeparentid= @NodeId and NodeClassID = @nodeclassid //*** query with number-seacrh, no text seacrh

This query works very fast, and all code before it does the same.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/15/2010 3:29:52 AM
   
RE:Perfomance, cache and expensive queries
Hello,

There shouldn't be any problem, if you are modifying just th query specific to your document type.

Best regards,
Boris Pocatko