Was doing some tunnings and got better results already.
Was using a t3.medium mysql instance with 650k process instances, some of them with open incidents, and acess the main cockpit and a process definition page too.
There was 2 slow queries:
select count(distinct RES.ID_ ) from ACT_RU_EXECUTION RES inner join ACT_RE_PROCDEF P on RES.PROC_DEF_ID_ = P.ID_ WHERE ( RES.PARENT_ID_ is null and ( P.ID_ = “teste-processo:1:7ce661a4-b3ff-11ef-936a-fe1819a0d98d” ) ) and (RES.TENANT_ID_ is null )
It took 17s
Added this index and it goes to 1s now:
CREATE INDEX PROC_DEF_ID_PARENT_ID_TENANT_ID USING BTREE ON camunda.ACT_RU_EXECUTION (PROC_DEF_ID_,PARENT_ID_,TENANT_ID_);
Also found that the count query for the activities to show a process definition took 32s:
select distinct RES.* from ( select ACTID.ACT_ID_ as ID_, INSTANCE.INSTANCE_COUNT_ , INC.INCIDENT_TYPE_ , INC.INCIDENT_COUNT_ from ( select distinct ACT_ID_ from ( select distinct E.ACT_ID_ from ACT_RU_EXECUTION E
where E.PROC_DEF_ID_ = “teste-processo:1:7ce661a4-b3ff-11ef-936a-fe1819a0d98d” and E.IS_ACTIVE_ = 1 and E.ACT_ID_ is not null and (E.TENANT_ID_ is null ) UNION select distinct I.ACTIVITY_ID_ AS ACT_ID_ from ACT_RU_INCIDENT I where I.PROC_DEF_ID_ = “teste-processo:1:7ce661a4-b3ff-11ef-936a-fe1819a0d98d”
and I.ACTIVITY_ID_ is not null ) ACTID ) ACTID
left outer join ( select E.ACT_ID_ , count(distinct E.ID_) as INSTANCE_COUNT_ from ACT_RU_EXECUTION E where E.PROC_DEF_ID_ = “teste-processo:1:7ce661a4-b3ff-11ef-936a-fe1819a0d98d” and E.IS_ACTIVE_ = 1 and
(E.TENANT_ID_ is null ) group by E.ACT_ID_ ) INSTANCE on ACTID.ACT_ID_ = INSTANCE.ACT_ID_ left outer join
( select I.ACTIVITY_ID_ , I.INCIDENT_TYPE_ , count(distinct I.ID_) as INCIDENT_COUNT_ from ACT_RU_INCIDENT I where I.PROC_DEF_ID_ = “teste-processo:1:7ce661a4-b3ff-11ef-936a-fe1819a0d98d”
and (I.TENANT_ID_ is null ) group by I.ACTIVITY_ID_, I.INCIDENT_TYPE_ ) INC on ACTID.ACT_ID_ = INC.ACTIVITY_ID_ ) RES order by RES.ID_ asc LIMIT 2147483647 OFFSET 0
The main reason was that it always goes to a very bad index using TENANT_ID_ and my tenant is always null…
After i droped these two index it goes to only 6s:
alter table ACT_RU_INCIDENT drop index ACT_IDX_INC_TENANT_ID;
alter table ACT_RU_EXECUTION drop index ACT_IDX_EXEC_TENANT_ID;
Maybe ill find a better way instead of drop the default ones