I am having a lot of trouble with the inefficiency of node_save(). But is node save my problem? That's ultimately what I am trying to find out.
I created a loop with 100,000 iterations. I created the bare minimum for the node object to be valid and save correctly. Here is the node save code:
$node = new stdClass();
$node->type = "test_page";
node_object_prepare($node);
$node->uid = 1;
$node->title = $node_title;
$node->status = 1;
$node->language = LANGUAGE_NONE;
if($node = node_submit($node)){
node_save($node);
}
Here are the results:
100,000 nodes were saved, each using node_save(). It took 5196.22 seconds to complete. That is ONLY 19 saves a second.
To say the least, that is not acceptable, especially when this person is getting around 1200 individual insert queries per second, and this person is getting 25,000 inserts per second.
So, what's going on here? Where is the bottleneck? Is it the with the node_save() function and how it's designed?
Could it be my hardware? My hardware is a development server, no one on it except for me - Intel dual core, 3Ghz, Ubuntu 12.04 with 16 gigs of ram.
While the loop runs my resource usage is: MySQL 27% CPU, 6M RAM; PHP 22% CPU 2M RAM.
My mysql configuration was done by the percona wizard.
Mysql says that if my CPU usage is under 70% my problem is disk bound. Granted, I have only a run of the mill WD Caviar 7200 RPM, but I should be getting more than 19 inserts a sec with it I hope!
Not too long ago I wrote about saving 30,000 nodes in a day. However, to be clear, this node has nothing to do with any external forces. It's purely a benchmark to learn about how to increase the speed of calls to node_save().
Realistically, I need to get 30,000 items into the database every minute using node_save. If node save is not an option, I wonder if I can write my own drupal api function "node_batch_save()" or something that takes advantage of mysql's ability to to do bulk inserts with the INSERT query. Thoughts on how to approach this?