• Resolved Marcus Fridholm

    (@marcusfridholm)


    I chose this plugin for an intranet I’m working on. It seemed simple and clear, and in general to be doing what I needed.

    I added the groups I needed, just short of 40, then categories to match them, and parent pages for each. Roughly 40 categories and top-level pages plus another 10 or so subpages.

    Since the groups aren’t hierarchical, a lot of pages and categories have more than group assigned to them, on average two.

    I now started adding posts to a couple of the categories, about 70 posts in all.

    While I was working the system got slower and slower, not so much in the admin area as in the front.

    So I installed debug objects to see wtf was going on. And noted that on the same page where I had 18 (eighteen) queries without UAM, i had 10302 (ten thousand threehundred and two queries I sh*t you not!) with the plugin active.

    Total query time: 1 392,1ms for 10302 queries (1,392127990722656s)
    Page generated in 4 000,0ms; (4,6721889972686767578125s); 65,20% PHP; 34,80% MySQL

    In reality that means going from a page served in less than half a second to about four seconds on localhost and eight seconds on my actual host. Activating W3 total cache, the time got down to seven seconds, so that is still faaaaar too slow.

    I sat down and started to analyze the reported queries, to try to get why the sh*t hit the fan that way, and it turns out it is probably an iteration/recursivity problem.

    That is, rather than doing a single query and using the result to filter what is accessible or not, it asks for each and every restrictable object. In some cases it makes the same query three or more times per object almost consecutively.

    Like this:

    Time: 0.2ms (0.00022101402282715s)
    Query: SELECT object_id as id
    FROM wp_uam_accessgroup_to_object
    WHERE group_id = 1
    AND object_type = ‘category’
    Function: UamUserGroup->getObjectsFromType()

    Time: 0.2ms (0.00017690658569336s)
    Query: SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = ‘category’ AND t.term_id = 1 LIMIT 1
    Function: get_term()

    Time: 0.2ms (0.00018811225891113s)
    Query: SELECT object_id as id
    FROM wp_uam_accessgroup_to_object
    WHERE group_id = 1
    AND object_type = ‘category’
    Function: UamUserGroup->_getAssignedObjects()

    Time: 0.1ms (0.00014400482177734s)
    Query: SELECT COUNT(*)
    FROM wp_term_relationships AS tr,
    wp_term_taxonomy AS tt
    WHERE tr.object_id = ‘247’
    AND tt.term_id = ‘1’
    AND tr.term_taxonomy_id = tt.term_taxonomy_id
    AND tt.taxonomy = ‘category’
    Function: UamUserGroup->_isPostInCategory()

    Time: 0.2ms (0.00021100044250488s)
    Query: SELECT object_id as id
    FROM wp_uam_accessgroup_to_object
    WHERE group_id = 1
    AND object_type = ‘post’
    Function: UamUserGroup->_getAssignedObjects()

    And so on… for ever and ever and ever.

    So my choices are to accept the performance hit, go through and debug the 4000 lines of code in the plugin, or start over with another plugin.

    Alternative one is probably a deal-breaker, since either the customer or the customers host will flog me if I let this go live in its current condition.

    Alternative two would be doable if I can be fairly sure of success. The cost would be time, which I can pay if it works and not if it doesn’t.

    The third alternative means starting over, which is very unappealing but might be what it comes down to in the end.

    What I would like is for the plugin author to test and see if he can recreate the problem, and share what might be the offending method, if there are any workarounds and whether it is a simple fix or means a total rewrite.

    If it is something he can recreate and if it is doable to fix it within a reasonable time-frame, I am available to help.

    http://wordpress.org/extend/plugins/user-access-manager/

Viewing 8 replies - 76 through 83 (of 83 total)
  • Plugin Author GM_Alex

    (@gm_alex)

    You are right, file added.

    Thread Starter Marcus Fridholm

    (@marcusfridholm)

    OK, first impressions is that the changes are awesome. You have managed to kill off 19 out of twenty queries, which means the world in speed. You have also managed to lessen the memory footprint quite a lot.

    I can look into applying my changes, but I doubt they will make much difference. The whole point was to lessen the amount of queries, which your caching seems to do quite handsomely. Now let’s see if all bugs are killed, I will try a heavy install locally to see what happens.

    To give you some constructive criticism, you should make your code more self-explanatory. That is more verbose and with descriptive methods and variables. This would make the architecture easier to trace and follow.

    In comments make good and descriptive use of @description, @parameter but also @uses and @return when applicable, that is if you cant name the internal methods and global variables in a way that makes such comments superfluous.

    Also, class-descriptions like: “The UamUserGroup class file.”, is mostly useless waste of space. It’s like “doh, I never would have guessed…”.

    Descriptions should be more like: “The UamUserGroup class is a helper class for UserAccessManager, which is instantiated from within the base class. It mostly contains functions for defining user groups and roles with helper methods for filtering and user handling.”

    Lastly I kind of wonder why there are three classes, the separation between them seems a little unclear and sometimes what you would expect happens in one class seem to happen in another. There might be a point to it, I just don’t get it.

    edit
    Oh, one more: For me one method calling on another calling on a third may be relevant from a redundancy perspective, but from a readers perspective it is easier to follow if the first method calls the other two in turn, making use of the first result to call the second. Digging into someone elses code can be rather frustrating as it is… 😀

    Plugin Author GM_Alex

    (@gm_alex)

    Thanks for the critic but I used phpDocumentor on all functions and classes to describe what I have done. And a class which is called UamUserGroup is a user group model with a prefix, which should be clear in my opinion. The phpDocumentor standard expects also a description for the file and the class and the classes have some descriptions with “more” sense, for me there is not so much to say about, but ok I’m developer and I know what happens there. I will extend the descriptions a little more in the future. There classes are doing the following:

    • Manage the user groups (UamUserGroup | Model)
    • Handle the access and check permissions (UamAccessHandler | Model)
    • Stick everything together (UserAccessManager | Controller)

    But note I didn’t make it clean MVC, so it’s some kind of mixing.

    Thread Starter Marcus Fridholm

    (@marcusfridholm)

    Ah, don’t take my criticism too seriously. Overall I’m impressed by the scope of your project and most things became clear enough when looking at the methods themselves.

    Actually, thank you.

    You’ve created a plugin for user/group/content handling that is very easy to grasp and use. If someone doesn’t realize it already, that is not a trivial task, especially not alone and outside of paid work.

    If this new version holds up through my testing, my last gripe with the plugin is gone. It looks to be amazingly much faster than before.

    Plugin Author GM_Alex

    (@gm_alex)

    Thanks for the feedback. It would be nice if somebody else could test the dev version and if everything went well I’ll prepare it for release.

    I tested the dev version on our test server, and everything appeared to be stable. It’s hard to compare speed on our test server site, because we have very few posts. But, everything was loading very smoothly, my user groups / assigned posts were still in tact, etc.

    Looking forward to the release of the updated version! Thanks for your work on this.

    Plugin Author GM_Alex

    (@gm_alex)

    New version is out now.

    Hi GM_Alex
    Im in a middle of a deadline today, but I hope to run a test with the new version on my current “slow as hell Worpdress install version”, means no changes so the comparing will be honest.

Viewing 8 replies - 76 through 83 (of 83 total)
  • The topic ‘Repeated queries and scalability’ is closed to new replies.