Performance optimilization for relationships


we are currently in the process of finding a solution for some performance issues we face when working with SugarCRM. On my local development environment I try to add tags to 100 accounts. I do this by first creating a specific amount of tags in the database using the beanfactory ($bean = BeanFactory::newBean('Tags') ... etc) and after that adding the tags to the account using the load_relationship -> add method. Just plain SugarCRM logic. 

This is an 'empty' default sugar 8.0.1 instance that I've constructed. What I see is that it takes almost 700 milliseconds to create a single tag and another 400 milliseconds for adding that tag to the relationship between accounts -> tags. I was wondering if there are any steps I can undertake to improve the performance. From my research I already found out that it isn't better to just add the id's to the relationship->add() method because the link2 class will first fetch the entire bean because of logichook functionality. 

Another approach I thought about was adding the relationship myself to the tag_bean_rel table but this is something I want to prevent at all times because this means talking directly to the database and ignoring any business logic. As said this is a default 801 install so the main question here is: Are there any settings or code that I can use to increase performance while adding new records to the database and relate these beans to another records? Is there some sort of bulk method?

  • Could you try using XHProf to determine where the time is being spent?

  • That was exactly what I did after I created the topic. What I noticed was the following: 


    Since I do this with the admin user ( hence the id 1 ) I was wondering why the framework tries to retrieve the same user over and over again. So I checked the source of sugarbean and noticed the property 'skipSecondaryQuery' property that can be used for retrieving a sugarbean with the beanfactory. This seems to speed up things a little because, from my point of view, it does not load other beans such as the user and all that. Is that assumption correct?

    I also disabled the activity stream before the script starts and enable it again when the script is done. This seems to increase performance also. Are there any other things I could do to improve performance like increasing the amount of beans cached or something similar?