Using the built-in XML writer class will help simplify a lot of the generation code plus hopefully save a little bit of memory, if not maybe make it faster. I need to get a patch and then compare the before & after for sitemap generation.

Comments

dave reid’s picture

The D6 version needs to add a requirements check to ensure the class exists, as XMLWriter is included by default only as of PHP 5.1.2.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new7.99 KB

Initial performance testing:

w/o patch - small set

Requests per second:    2.02 [#/sec] (mean)
Time per request:       495.363 [ms] (mean)
Time per request:       495.363 [ms] (mean, across all concurrent requests)
Transfer rate:          0.81 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   419  495  65.5    479     834
Waiting:      419  495  65.5    479     834
Total:        419  495  65.5    479     834


w/ patch - small set

Requests per second:    2.01 [#/sec] (mean)
Time per request:       498.409 [ms] (mean)
Time per request:       498.409 [ms] (mean, across all concurrent requests)
Transfer rate:          0.80 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.4      0      20
Processing:   427  498  66.9    482     831
Waiting:      427  498  66.9    482     831
Total:        427  498  66.9    484     831

--------------------------------------------------------------------------------

w/o patch - medium set

Requests per second:    0.26 [#/sec] (mean)
Time per request:       3777.781 [ms] (mean)
Time per request:       3777.781 [ms] (mean, across all concurrent requests)
Transfer rate:          0.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:  3685 3778  82.3   3760    4065
Waiting:     3685 3778  82.3   3760    4065
Total:       3685 3778  82.3   3760    4065


w/ patch - medium set

Requests per second:    0.26 [#/sec] (mean)
Time per request:       3806.549 [ms] (mean)
Time per request:       3806.549 [ms] (mean, across all concurrent requests)
Transfer rate:          0.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:  3695 3806  90.4   3788    4167
Waiting:     3695 3806  90.4   3788    4167
Total:       3695 3806  90.4   3788    4167

So we get a marginal time difference. However, the memory usage shows something interesting:

At end of generation, the result of memory_get_peak_usage(TRUE):
Without patch: 7077888
With patch: 6815744

Patch saved about 256 KB with about 7000 nodes. I'm not sure if this should proceed or not.

Anonymous’s picture

Since it is slower my gut feel is a no go but reduced memory is also a performance factor. However, the speed of this module is more important due to its nature.

dave reid’s picture

Yeah I think I need to test with an even bigger data set. The percentage difference for memory usage was way more than the percentage difference in execution.

hass’s picture

If you explain me how to collect the stats I'm able to run this tests on a site with 150.000 nodes, 2000 taxonomy term...

dave reid’s picture

I created a 'test.php' file in my Drupal's root folder:

include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
module_load_include('generate.inc', 'xmlsitemap');
xmlsitemap_run_progressive_batch('xmlsitemap_regenerate_batch');
exit();

And then run the apache ab benchmarking command & record results from before & after patch:
ab -c 1 -n 25 http://mysql.drupal7dev.local/test.php

If you have a smaller data set, you can change the 'n' paramter to a higher value, but for a large data set I wouldn't recommend going over 25 loops.

dave reid’s picture

Ok so I think I've finally come up with a compelling reason why we should make this switch. #786510: Contexts should be able to alter the XML header output (and possibly link output?) needs other modules to be able to modify the XML schema and individual XML link elements. That's super easy to do with XMLWriter were we can pass the writer object or the element object to the alter functions. Currently it's not easy to do otherwise.

hass’s picture

Sorry, for testing I need a D6 patch... this big testing site is D6 only.

dave reid’s picture

StatusFileSize
new7.52 KB

Here's the patch against the current DRUPAL-6--1 branch.

dave reid’s picture

Anyone? :/

Anonymous’s picture

Is there some reason to hang onto

-  if (!$status) {
+  /*if (!$status) {
     trigger_error(t('Unknown error occurred while writing to file @file.', array('@file' => $file)));
   }
   elseif (xmlsitemap_var('gz')) {
     $file_gz = $file . '.gz';
     file_put_contents($file_gz, gzencode(file_get_contents($file), 9));
-  }
+  }*/

or did you just forget to remove it in the final?

dave reid’s picture

I'm not sure how I'm going to handle that. I may just remove the $status handling everywhere. At this point I'm more concerned about performance testing to see that this isn't going to be horrible change.

Anonymous’s picture

I'm not setup to do performance testing. Maybe one of the users with 50K or more can give the change a try.

Status: Needs review » Needs work

The last submitted patch, 764658-xmlsitemap-xmlwriter-D7.patch, failed testing.

moshe weitzman’s picture

FWIW, I have always done my XML writing with core's format_xml_elements() but I never had a huge dataset.

dave reid’s picture

Yeah the problem is that we need to allow other modules to alter stuff in the XML head, namespaces, etc. I would think we'd get better performance using the native XMLWriter rather than generating large amounts of arrays (or a large number of separate small arrays). I'm going to move ahead with this issue this weekend as it's blocking other good patches from going in. If we encounter any major problems (none discovered in testing so far), it is possible to rollback.

dave reid’s picture

I'm going to proceed with this since it has not gotten any reviews and is blocking a major feature.

dave reid’s picture

Priority: Normal » Critical
dave reid’s picture

StatusFileSize
new10.72 KB

OMG yes this is exactly the approach I want to do because this allows us to extend the XMLWriter into our own XMLSitemapWriter class and also allows us to override XMLWriter::flush to keep track of the file writing status.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new10.72 KB

Revised patch

dave reid’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)
dave reid’s picture

Status: Patch (to be ported) » Fixed
StatusFileSize
new10.5 KB

Committed this to CVS on 6.x-2.x as well.
http://drupal.org/cvs?commit=413422

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.