Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Textpattern latency problem
Howdy!
I’m working on the finishing touches of a certain TXP-driven site, and I’m having a lot of trouble with the speed of Textpattern building some of the intensive pages. Speeding up the site is a major priority before it goes live.
It’s worst on certain individual article pages, which include two zem_contact forms that allow users to flag the article information for moderation— this site publishes user-submitted content, and it’s important to give users a way to message us when the information is bad. Embedding the ZCR forms in the article allows me to include stuff in the eMail message, through zem_contact_secret fields, that will be helpful to the moderator, including an article ID, and a link to edit the article in Textpattern.
I mention the ZCR forms because when I comment them out using txp:hide
, there is a noticeable improvement in the page load time. Removing the ZCR forms would also allow me to enable caching for those pages, much as I hate to modify core Textpattern files.
What other ways could I allow users to flag content without a zem_contact form? I’d be interested in any design patterns or solutions that have worked for you, as well as any best-practices advice you may have. Is there a javascript or other method to report an item for moderation? Is there an AJAX way to load the ZCR forms only if someone clicks on “Flag this item” link? (Right now, the link triggers jquery’s block_ui and renders the pre-loaded ZCR form.) If there is a simple, lean solution, I’m keen to learn it!
I’ve found Textpattern to be a swift CMS in most cases, and I have successful experience of speeding up Textpattern in the past. Obviously, I’m checking and attending to other standard things that could be slowing the browser down, but this seems to be a slowness in building rather than loading the page.
Thanks for all the warmth, guidance, and support! I appreciate your thoughts!
Last edited by johnstephens (2009-11-13 19:11:59)
Offline
Re: Textpattern latency problem
Check your tag trace for clues on what might cause the increase in page load time.
Can you provide some real numbers (SQL+parse) to indicate what the difference is with/without ZCR on the same page?
Offline
Re: Textpattern latency problem
Thanks, Ruud. I’ve doing a full inventory of the tag trace now.
How do I find SQL+parse numbers? I see Runtime
, Query time
, and Queries
in the tag trace— I’m guessing Query time
is SQL— does Runtime
quantify parse?
Offline
Re: Textpattern latency problem
I was wrong. This situation is unrelated to ZCR— the runtime and query time numbers show virtually no difference when I comment out the ZCR forms.
The problem is caused by a certain article_custom tag I have, which causes the page to load almost thirty times slower:
<txp:article_custom
section="publications"
publication_title='<txp:custom_field name="publication_title" />'
limit="1"
form="_publication-info" />
The purpose of this tag is to show publication info that goes with each article— the site groups articles by publication, and each publication has its own record in the textpattern
table. Articles are grouped with their publication using a custom field.
When I open the page without this tag, it loads like lightnight†:
<!-- Runtime: 0.2209 -->
<!-- Query time: 0.090051 -->
<!-- Queries: 39 -->
When I use the article_custom tag above, it seems to take forever:
<!-- Runtime: 6.0600 -->
<!-- Query time: 0.168417 -->
<!-- Queries: 42 -->
<!-- Memory: 5538Kb, <txp:site_url/> -->
I’m not sure how to work around this. I need the publication info on each article. Is there a simpler query I could plug into smd_query or some other method to output this article info, without accosting visitors with such an oppressive load time?
†All these tests are on my dev server, not the publish server.
Last edited by johnstephens (2009-11-13 19:30:50)
Offline
Re: Textpattern latency problem
What’s the actual SQL query that’s running? In debug mode, it should be somewhere near that tag. Once you get that, run explain <your-query>;
in the mysql client to get some info on how MySQL is executing the query. Chances are you’ve got a ton of rows, so you may want to try adding an index to publication date’s column (custom_n) and see if that speeds it up.
Offline
Re: Textpattern latency problem
Thank you, Jon-Michael! I don’t understand the results but here is what I found; first, the query [SQL (0.0852971076965)]:
EXPLAIN SELECT * , UNIX_TIMESTAMP( Posted ) AS uPosted, UNIX_TIMESTAMP( Expires ) AS uExpires, UNIX_TIMESTAMP( LastMod ) AS uLastMod
FROM textpattern
WHERE 1 =1
AND STATUS =4
AND Posted <= NOW( )
AND (
NOW( ) <= Expires
OR Expires = '0000-00-00 00:00:00'
)
AND Section
IN (
'publications'
)
AND custom_17 LIKE 'Library'
ORDER BY Posted DESC
LIMIT 0 , 1;
MySQL said:
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
---|---|---|---|---|---|---|---|---|---|
1 | SIMPLE | textpattern | range | Posted,section_status_idx,Expires_idx | section_status_idx | 198 | NULL | 5112 | Using where; Using filesort |
I’m very grateful for your help!
Last edited by johnstephens (2009-11-16 16:02:34)
Offline
Re: Textpattern latency problem
jm wrote:
Chances are you’ve got a ton of rows, so you may want to try adding an index to publication date’s column (custom_n) and see if that speeds it up.
I do have a ton of rows, but I’m not sure how to add an index to a column, or what that means. Would that speed up this query? How do I do it?
Offline
Re: Textpattern latency problem
Okay, I figured out how to add an index to the custom field used to group articles in the “articles” section with publication info articles in my “publications” section— I added a row to the “Indexes” section of my textpattern table, with type: INDEX.
This slightly reduced the Runtime, using the same Textpattern markup:
<!-- Runtime: 5.5567 -->
<!-- Query time: 0.049956 -->
<!-- Queries: 45 -->
I’d like to cut that at least in half, if not more. Is there a more efficient query I could use to display a single record from the “publications” section appropriate to the current article, relating based on the custom field value?
The current query that Textpattern creates from my custom field tag is this:
SELECT * , UNIX_TIMESTAMP( Posted ) AS uPosted, UNIX_TIMESTAMP( Expires ) AS uExpires, UNIX_TIMESTAMP( LastMod ) AS uLastMod
FROM textpattern
WHERE 1 =1
AND STATUS =4
AND Posted <= NOW( )
AND (
NOW( ) <= Expires
OR Expires = '0000-00-00 00:00:00'
)
AND Section
IN (
'publications'
)
AND custom_17 LIKE 'Library'
ORDER BY Posted DESC
LIMIT 0 , 1
Are there other methods to optimize my code for better performance when dealing with large amounts of data?
Last edited by johnstephens (2009-11-18 03:10:19)
Offline
Re: Textpattern latency problem
Please time this, and report back:
<txp:article_custom
section="publications"
publication_title="Library"
limit="1"
form="_publication-info" />
Offline
Re: Textpattern latency problem
Thank you Robert! Here are the results:
<!-- Runtime: 5.8091 -->
<!-- Query time: 0.052040 -->
<!-- Queries: 45 -->
It removed on layer of abstraction, but the difference wasn’t significant. Hmm.
Offline
Re: Textpattern latency problem
Unveiling yet another layer, we would need to look at your _publication-info
form and could try this to remove it from this lab’s subject:
<txp:article_custom
section="publications"
publication_title="Library"
limit="1"><txp:title /></txp:article_custom>
Offline
Re: Textpattern latency problem
<!-- Runtime: 0.1356 -->
<!-- Query time: 0.028248 -->
<!-- Queries: 39 -->
It’s the form! Oh my.
Offline