fwrite() is called 5 times in _xmlsitemap_create_cache_chunk(); in each call, the function is called to output part of a constant string.
Rather than calling 5 times the function, it would be better to call it only once, but passing to it the full string.

Comments

avpaderno’s picture

fwrite() is also called 6 times to output the sitemap data for a single link. Adding 6 times with the previously reported 5 times, plus one call more to output the closing sitemap tag, in a sitemap with just 2 links fwrite() is called 18 times; for a sitemap with 100 links, the function is called 606 times.
Using different code, in a sitemap with 100 links, the function could be called just 102 times. The difference with the actual code is 504 calls less, when the number of links is just 100.

avpaderno’s picture

In general, if n is the number of links in a sitemap chunk, the actual code calls fwrite (n + 1) * 6 times, while a different implementation would call the same function n + 2 times. For a sitemap chunk with 1000 links the number of times the function is called would be 6006 times versus 1002.

Anonymous’s picture

Status: Active » Postponed
Issue tags: +remind

Changed you mind on the change you did? Check the 5.x code and you'll see that it sets a variable and then calls fwrite(). I'm leaning toward, not worth fixing at this point.

avpaderno’s picture

See the code I developed before you rolled it back to beta0; Drupal 5 branch changes were secondary, and it's not said I would promptly update it to the latest developed code for Drupal 6.

dave reid’s picture

I did some benchmarking on 6.x-2.x to see compare calling fwrite often vs one time per link. The test ran a full drupal bootstrap that just called xmlsitemap_regenerate(). My sitemap was split into two chunks and had only about 6500 links total. The sitemap index and chunks were generated twice for english and french languages. Ran ab -n 50 http://mysql.drupal6dev.local/test.php

OId code (fwrite called 6 times per link)

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

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:  2605 2741  57.8   2752    2827
Waiting:     2597 2736  57.8   2746    2827
Total:       2605 2741  57.8   2752    2827

Optimized code (1 fwrite per link):

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

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:  2370 2546  44.6   2544    2649
Waiting:     2365 2542  45.4   2542    2649
Total:       2370 2546  44.7   2544    2649

So with a fairly small sitemap, it resulted in about 200ms of an improvement which is a small, but worthwhile step that will become a greater difference as the sitemap grows larger. Thanks Kiam! I have implemented this change in 6.x-2.x with http://drupal.org/cvs?commit=224204.

Anonymous’s picture

Assigned: Unassigned »
Anonymous’s picture

Status: Postponed » Active
dave reid’s picture

Status: Active » Fixed

Committed to 6.x-1.x CVS.
http://drupal.org/cvs?commit=259914

Status: Fixed » Closed (fixed)
Issue tags: -remind

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