The code to calculate the sitemap chunks size contains the following IF-statement:

  if (($link_count / $chunk_size) > 1000) {
    $chunk_size = (integer) $link_count / 1000;
    // ...
  }

Taking the assumption that the current chunk size is 1000, the IF-statement condition is verified when the number of links ($link_count) is at least 1000001; taking the assumption that the number of links is exactly 1000001, then the chunk size will be changed to 1000 ((integer) 1000001 / 1000 => (integer) 1000.001 => 1000).
In other words, the chunk size doesn't get changed at all, despite the fact the number of links would need more than 1000 sitemap chunks.

CommentFileSizeAuthor
#11 xmlsitemap-485632.patch4.18 KBAnonymous (not verified)
#9 xmlsitemap-485632.patch4.05 KBAnonymous (not verified)
#5 xmlsitemap-485632.patch3.66 KBAnonymous (not verified)

Comments

Anonymous’s picture

Priority: Normal » Critical
avpaderno’s picture

I hope the solution of the problem will not be to adopt the code I wrote. That would be in contrast of the description given to the code I developed in the past weeks, which has been described someway like a mistake; it would not make sense to criticize the code, and then adopt it.

Anonymous’s picture

Kiam, not everything you did was a mistake. The mistake was trying to transform the 1.0 version into something more than it was meant to be. I tried to explain that to you in a number of issues but you went forward with your plan anyway which cost us time. It is now time to move past the hurt. I appreciate your taking the time to raise the issues that you know needs to be addressed. It helps with the transformation.

avpaderno’s picture

Kiam, not everything you did was a mistake.

It doesn't seem what somebody else said in another issue report, where the blame was put on me.
Rather than complaining about the code developed by somebody else (when you are using it), it would be better to go forward without to make any comments about that. If you are free to say your opinion about the developed code, I am free to make notice what it's true, and what it's not true.

Then, the decision to roll-back the code to the point that some features, approved by two maintainers one month ago, were removed was yours.

Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new3.66 KB

How does this look?

dave reid’s picture

I'm not sure what the usefulness of this section of code in xmlsitemap_chunk_count() is:

+  $chunk_count = (integer)($link_count / $chunk_size);
+  if ($chunk_count != ($link_count / $chunk_size)) {
+    $chunk_count++;
+  }

The variable $chunk_count is getting assigned a value and then getting compared to the value again? Why not just do $chunk_count = ceil($link_count / $chunk_size);

The chunk size adjustment code in xmlsitemap_output() would be even better with some inline comments. It was hard for me to see what was happening there and why each calculation was needed.

Why change the default chunk size from 1000 to 50,000? But then leave the chunk-size-changing code in? Why not leave the default at 1000?

Anonymous’s picture

It's an old school way of a ceil function when ceil functions didn't exist. It's hard to lose some things. I will use ceil($link_count / $chunk_size) instead.

I was already mulling over the default value and wasn't happy with it. I'll change it back to 1000 but use a constant XMLSITEMAP_DEFAULT_SITEMAP_LINKS.

avpaderno’s picture

1000 was a value chosen as a compromise between a too low value, and a too big value; that value should allow sites like drupal.org to have a sitemap with the correct number of sitemap chunks.

Anonymous’s picture

StatusFileSize
new4.05 KB

I struggled with the comment. How can it be worded better?

avpaderno’s picture

I find the code hard to be understood; I don't understand the full operation of subtracting a value, and then adding another value.

May you explain the purpose of the code?

Anonymous’s picture

StatusFileSize
new4.18 KB

Does the added comments help?

If we have a chunk size of 10 and we have a link count of 10001 which is 1001 chunk files for the index which is over the maximum. We will change the chunk size to 20 which will give us 501 chuck files to index. As the chunk size increases, if the rate of site links remain constant it will take longer to overrun the sitemap index with each increment.

If we have a chunk size of 10 and we have a link count of 10011 which is 1002 chunk files and is 2 files over the maximum; we will change the chunk size to 30 ((10 * 2) + 10) which will give us 251 chunk files to index. A site that overruns the maximum by more than 1 chunk file is an active site. We hope to find a happy chunk size that is livable and doesn't exceed the site links maximum and doesn't cause us to adjust the chunk size for each view of the sitemap.

avpaderno’s picture

Thanks for the reply, earnie.
I have another question. Supposing that the chunk site is set to 1000, and it must be increased, would not to set it to 1100 the simpler way of increasing its value? In that way, the chunk size would not be changed every time the number of links is greater than the previous value by one, and the code does not need to verify any conditions.

Anonymous’s picture

CS = Chunk Size
LC = Link Count
CF = Chunk File count
MI = Maximum Index count

1000 CS * 1000 MI = 1000000 LC
1100 CS * 1000 MI = 1100000 LC
2000 CS * 1000 MI = 2000000 LC
3000 CS * 1000 MI = 3000000 LC

1000001 LC / 1000 CS = 1001 CF
1000001 LC / 1100 CS = 910 CF (Kiam's suggested adjustment).
1000001 LC / 2000 CS = 501 CF (Earnie's coded adjustment).

1001001 LC / 1000 CS = 1002 CF
1001001 LC / 1100 CS = 911 CF (Kiam's suggested adjustment).
1001001 LC / 3000 CS = 334 CF (Earnie's coded adjustment).

I would rather adjust the CS fewer times as I have it coded. With adding just 100 for each adjust we will soon adjust it again for the busier sites.

avpaderno’s picture

My suggestion was not to simply add 100.

With the code I used, the first time the links are more than 1000000, the chunks size is raised to 1100; when the number of links is greater than 1100000, the chunk size is raised to 1200; when the number of links is greater than 1200000, the chunk size is raised to 1300.
This means that the chunk size is changed every time the number of links is increased of more than 100000 new links, which does not happen in few time.
To notice also that, if the number of links passes from 999999 to 1200006, the chunk size is directly changed to 1300.

The code I am referring for the calculus of the new chunk size is $new_size = (integer) ceil($link_count / 100000) * 100.

Anonymous’s picture

Ok, now we are talking semantics of preference (my bikeshed is blue and your's is red). Therefore my preference is still standing (I prefer my bikeshed to be blue) unless Dave objects I will commit the code later today.

dave reid’s picture

I wanted to try and compare this to how the chunk size is calculated in 6.x-2.x, but it seems it's not too different. Whenever the sitemap files are regenerated and the 'auto' chunk-size is enabled, we simply run this function once to reset and recalculate the chunk size value:

function xmlsitemap_get_chunk_size($reset = FALSE) {
  static $size;
  if (!isset($size) || $reset) {
    $size = xmlsitemap_var('chunk_size');
    if ($size === 'auto') {
      $count = max(xmlsitemap_get_link_count($reset), 1); // Prevent divide by zero.
      $size = min(ceil($count / XMLSITEMAP_MAX_SITEMAP_LINKS) * 1000, XMLSITEMAP_MAX_SITEMAP_LINKS);
    }
  }
  return $size;
}

I tested the function with a *lot* of different link counts and think I came up with a pretty good system that doesn't get too wacky:

Links: 500      	Chunk size: 1000  	Chunk count: 1   
Links: 750      	Chunk size: 1000  	Chunk count: 1   
Links: 1000     	Chunk size: 1000  	Chunk count: 1   
Links: 2500     	Chunk size: 1000  	Chunk count: 3   
Links: 5000     	Chunk size: 1000  	Chunk count: 5   
Links: 7500     	Chunk size: 1000  	Chunk count: 8   
Links: 10000    	Chunk size: 1000  	Chunk count: 10  
Links: 25000    	Chunk size: 1000  	Chunk count: 25  
Links: 50000    	Chunk size: 1000  	Chunk count: 50  
Links: 75000    	Chunk size: 2000  	Chunk count: 38  
Links: 100000   	Chunk size: 2000  	Chunk count: 50  
Links: 101000   	Chunk size: 3000  	Chunk count: 34  
Links: 102000   	Chunk size: 3000  	Chunk count: 34  
Links: 250000   	Chunk size: 5000  	Chunk count: 50  
Links: 500000   	Chunk size: 10000 	Chunk count: 50  
Links: 750000   	Chunk size: 15000 	Chunk count: 50  
Links: 1000000  	Chunk size: 20000 	Chunk count: 50  
Links: 2500000  	Chunk size: 50000 	Chunk count: 50  
Links: 5000000  	Chunk size: 50000 	Chunk count: 100 
Links: 7500000  	Chunk size: 50000 	Chunk count: 150 
Links: 10000000 	Chunk size: 50000 	Chunk count: 200 
Links: 25000000 	Chunk size: 50000 	Chunk count: 500 
Links: 50000000 	Chunk size: 50000 	Chunk count: 1000

So we start out with a 1000 minimum chunk size and we focus more on increasing the chunk size and keeping a lower chunk count, because it means fewer files to be generated, and fewer large SQL queries to execute. We don't reach the maximum chunk size until the site has 2.5 million links, which is probably around the high-end of sites using the module.

So in general, I prefer to make larger chunk size adjustments like earnie has proposed.

Anonymous’s picture

Status: Needs review » Fixed

Committed to CVS

Anonymous’s picture

Dave, once 50M links are reached you don't warn the user. Is it feasible to consider an index file of index files? Yea, I know it is an edge case waiting to happen but what if?

dave reid’s picture

Currently the 6.x-2.x module will not pass the 50,000 links per chunk, but will go on and create more chunks than the 1000 specification limit. Note that there is already a warning in http://project.davereid.net/api/function/xmlsitemap_requirements/xmlsitemap that says to reduce the number of links, and I've already add another requirements check for more than 50 mil links locally, but just need to commit.

Status: Fixed » Closed (fixed)

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