Closed (fixed)
Project:
Drupal core
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
14 Jun 2004 at 12:47 UTC
Updated:
1 Dec 2004 at 23:16 UTC
Jump to comment: Most recent file
Caching the node object generated by node_load is a good idea as shown by the attached benchmarks.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | node-cache.patch | 1.54 KB | killes@www.drop.org |
| #19 | node-object_3.patch | 7.29 KB | killes@www.drop.org |
| #15 | node-object_2.patch | 1.98 KB | killes@www.drop.org |
| #14 | book_5.patch | 2.24 KB | killes@www.drop.org |
| #13 | node-object_1.patch | 1.85 KB | killes@www.drop.org |
Comments
Comment #1
killes@www.drop.org commentedHere is the patch. It slao make calling node_load without specifying node->nid unwise. Only poll.module needs to be fixed.
Comment #2
killes@www.drop.org commentedThat's a patch. The patch works well at my site. A patch for poll.module is forthcoming.
Comment #3
killes@www.drop.org commentedHere is an improved atch which does obliterate the patch to poll.module. Calling node_load without specifying node->nid is still safe.
Comment #4
dries commentedDo you have performance numbers?
Comment #5
killes@www.drop.org commentedThe first attachement to this task. There seems to be still a problem with viewing polls. Needs investigation. This patch is very helpfull if you use many node types that use the _load hook (flexinode, event, ...).
Comment #6
killes@www.drop.org commentedThe problem with poll.module is that its load hook's action depends on the uid of the user. This is legitimate use I guess. Anybody got an idea on how to work around that?
Comment #7
killes@www.drop.org commentedUpon reading some poll.module code, I think that we could move the user specific part to poll_view. Opinions?
Comment #8
killes@www.drop.org commentedSteven and I had a second look at the patch. As a result, revisions aren't cached anymore (they don't appear on node listings anyway) and bootstrap.inc doesn't need patching anymore.
Comment #9
killes@www.drop.org commentedSteven and I had a second look at the patch. As a result, revisions aren't cached anymore (they don't appear on node listings anyway) and bootstrap.inc doesn't need patching anymore.
Comment #10
Steven commentedHere is a current patch for the poll.module which moves the user-specific checks out of hook_load().
Comment #11
Steven commentedKeeping poll patch current.
Comment #12
killes@www.drop.org commentedBoth patches apply again. I want to stress that this patch is important to avoid several popular contrib modules (flexinode, event) becoming "site killers" by using the nodeapie "load" hook.
Comment #13
killes@www.drop.org commentedI've extended the patch to store the $node object in a static var. This fixes http://drupal.org/node/view/10145
Comment #14
killes@www.drop.org commentedThe book module needs a patch too.
It does the following:
It removes book_load. Treating nodes differently depending on if they are native book nodes or not makes no sense and is confusing for the user. This part of the codes was broken anyway.
It moves the query done in _nodeapi('view') to 'load' to take advantage of caching.
Comment #15
killes@www.drop.org commentedThe static var didn't make too much sense.
Comment #16
dries commentedThe book module change will result in extra database overhead because it is executed for each load. Secondly, mind to explain why the current code is broken?
Comment #17
killes@www.drop.org commentedThe load will be executed only once and with my node object caching the result will be stored in the cache.
The current code is broken do to
if (arg(1) == 'edit' && !user_access('administer nodes')) {
^
Comment #18
dries commentedBut if a call to node_load() turns out not to be non-cacheable, you'll pay the extra overhead. You are (incorrectly) assuming that the caching will always kick in.
Also, it is unclear whether the poll module patch is still required. Can you make a single patch with all required changes?
Comment #19
killes@www.drop.org commentedOk, here is an updated patch. It includes both the poll and the book patch. There is a small change from the previous patch: Only the last loaded node is cached in a static var. Otherwise the memory consumption would maybe have gone through the roof for a node/ page where the nodes have a lot of revisions.
I will provide new performance numbers shortly. I also believe that in most cases the cache _will_ kick in.
Comment #20
killes@www.drop.org commentedWithout this patch:
754ms +- 16.2 for /node, 43 queries in total, 2 polls, 8 other.
With patch:
725ms +- 5.3 for /node, 36 queries in total, 2 polls, 8 other.
The "other" node types have a query in nodeapi('load') like many have (forum, ...)
The patched version is faster by 4%.
Another run with 2 polls, 7 other, and one flexinode node with four fields:
With patch:
761ms +- 2.5, 39 queries
Without patch:
797ms +- 3, 49 queries
4% again.
2 polls, 6 other, 2 flexinodes
With
762ms +- 6.0, 39 queries
without
798ms +- 5.6, 50 queries
4.5%
While this 4.x% improvement may look insignificant to some, it is a good improvement if a lot of registered users keep coming back to your front page. Other pages will also benefit (all the ones that call node_load). Also, the cost is only one entry in the cache table per node.
Comment #21
Steven commentedThe "keep last node" part of this patch is interesting because on several pages, we do repeated node_loads for the same node, in succession:
- node.module, hook_menu: determine whether or not to show the edit and revisions tab
- node.module, when viewing a node
- poll.module, hook_menu: determine whether or not to show the poll results tab.
Also, someone might run a block which kicks in for node/id and displays extra info on the side. Such a block can now re-use the node object without having to query the db again and call hook_load/nodeapi('load').
Comment #22
(not verified) commentedIf for nothing else, for the "keep the last node" part, this patch is worth applying!
Comment #23
killes@www.drop.org commentedHere is an updated and simplified version of that patch. It will no longer store info in the DB but only use a static var.
Comment #24
dries commentedI tried the static/simple node caching patch with the Forum topics' and 'Book navigation' blocks enabled.
I get a 9% speedup for forum topics, and a 1% speedup for book pages. The patch eliminates 12 queries for the forum topic page, and 8 queries for the book page. On the forum page, there are no duplicate queries left. The main page is unaffected.
Comment #25
dries commentedCommitted to HEAD. Thanks.
Comment #26
(not verified) commented