( I've add new tip , see the latest reply)
Dear all, I would like to share experience about tuning openworklist function.
I success tune up from 3minute to less than 40 seconds for open worklist page.
And 3minute bindflow to less than 1 seconds.
My company use k2 . we currently have 400000 row in _worklist.
the user which having 500 task in worklist have problem when access worklist page, it take about 3 minutes or usually show timeout.
I investigate that k2 will use function openworklist when user click worklist button:
public static Worklist OpenWorklist(string user, string platform)
{
int num2 = 3;
string location = "K2Sql.OpenWorklist";
int num = 0;
Label_000D:
num++;
SqlConnection cn = null;
try
{
cn = new SqlConnection(m_Con);
cn.Open();
SqlCommand command = CreateCommand("kUserWorklist", cn);
command.Parameters.Add("@User", user);
command.Parameters.Add("@Platform", platform);
SqlDataReader dr = command.ExecuteReader();
Worklist worklist = LoadWorklistFromReader(dr);
worklist.m_TotalCount = worklist.Count;
dr.Close();
return worklist;
}
catch (Exception exception)
{
K2ErrorFile.Add(location, exception);
if (K2Util.IsThrowK2(exception))
{
throw exception;
}
if (num == num2)
{
throw new Exception("A database error occured");
}
TestConnection();
goto Label_000D;
}
finally
{
CloseConnection(cn);
}
return null;
}
As you see they will call stored procedure named: kUserWorklist
I check the stored and found this command
CREATE PROCEDURE kUserWorklist @User NVARCHAR(128), @Platform NVARCHAR(128)
AS
SET NOCOUNT ON
SELECT ProcID, ActID, EventID, w.ID, w.Status, w.Data, pi.ID, pi.Status, pi.StartDate, pi.Priority, pi.ExpectedDuration, pi.Folio, pi.Guid, EventInstID, EIPriority, EIExpectedDuration, EIStartDate, ActInstDestID, wh.ActInstID, AIPriority, AIExpectedDuration, AIStartDate, pf.Data, pf.Xml, af.Data, af.Xml
FROM _Worklist w (NOLOCK)
JOIN _WorklistHeader wh (NOLOCK) ON w.ProcInstID = wh.ProcInstID AND w.HeaderID = wh.ID
JOIN _ProcInst pi (NOLOCK) ON w.ProcInstID = pi.ID
JOIN _Field pf (NOLOCK) ON pi.ID = pf.ProcInstID AND wh.ProcInstFieldID = pf.ID
JOIN _Field af (NOLOCK) ON pi.ID = af.ProcInstID AND w.ActInstDestFieldID = af.ID
WHERE w.iUser] = @User AND (Platform = @Platform OR @Platform IS NULL) AND w.Status <> 4
GO
I use Microsoft Index Tuning Wizard and they advice to add 2 index:
CREATE CLUSTERED INDEX I_Field2] ON wdbo].u_Field] (;ProcInstID] ASC,
IF( @@error <> 0 ) SET @bErrors = 1
IF( @bErrors = 0 )
COMMIT TRANSACTION
ELSE
ROLLBACK TRANSACTION
BEGIN TRANSACTION
SET @bErrors = 0
CREATE CLUSTERED INDEX _Worklist1] ON ;dbo].S_Worklist] (=User] ASC, ProcInstID] ASC )
IF( @@error <> 0 ) SET @bErrors = 1
IF( @bErrors = 0 )
COMMIT TRANSACTION
ELSE
ROLLBACK TRANSACTION
/* Statistics to support recommendations */
CREATE STATISTICS ehind_69575286_2A_1A] ON Edbo]. _field] (CREATE STATISTICS Nhind_770101784_1A_2A_3A_4A_5A_6A_7A_8A_9A] ON CREATE STATISTICS Ihind_770101784_1A_5A_2A_3A_4A_6A_7A_8A_9A] ON dbo].b_worklistheader] (rprocinstid], dprocinstfieldid], [id], iactid], ceventid], dactinstid], daipriority], yaiexpectedduration], naistartdate])
CREATE STATISTICS Ihind_1899153811_3A_11A] ON _dbo].__worklist] ( procinstid], ruser])
after 20 minutes of index creation. All system much improved.
Next phase I will investigate other bottleneck.
If you have some advice about tuning , your welcome.