I've installed CDN (and removed parallel) and enabled the statistics to see what is going on.

It works as advertised, but I wonder if it would be possible to add a kind of round-robbin scheme if I add several subdomain urls? Ie. something like this:

css.example.com|.css
js.example.com|.js
cdn1.example.com
cdn2.example.com
cdn3.example.com

The assigned files will go from the assigned domains, and all others would use the other three domains to spread out the files. If I have 6 images the statistics would show:

Number of files served from the server http://cdn1.example.com: 2
Number of files served from the server http://cdn2.example.com: 2
Number of files served from the server http://cdn3.example.com: 2

Best case would be to have a round robbin scheme working if filetypes are assigned to two or more subdomains, and perhaps have a final catch all domain.

So this example:

css.example.com|.css
js.example.com|.js 
cdn1.example.com|.jpg
cdn2.example.com|.jpg
cdn3.example.com

would give me something like this if I have 4 jpgs, 1 ico and 1 png file served:

Number of files served from the server http://cdn1.example.com: 2
Number of files served from the server http://cdn2.example.com: 2
Number of files served from the server http://cdn3.example.com: 2

Would that be even more awesome?

Comments

wim leers’s picture

Title: Fallback to more than one cdn url? » Balance over multiple CDNs?
Assigned: Unassigned » wim leers
Category: feature » support
Status: Active » Fixed

Yes, this is possible, even with the version you have right now!

See the "When using multiple servers: picking a specific one based on some criteria" section in README.txt:


Or if you want to balance the number of files served by each CDN (i.e. on
average, each CDN serves the same amount of files on a page) instead of
picking the CDN based purely on filetype, one could write:
  /**
   * Implementation of cdn_pick_server().
   */
  function cdn_pick_server($servers_for_file) {
    $filename = basename($servers_for_file[0]['url']);
    $unique_file_id = hexdec(substr(md5($filename), 0, 5));
    return $servers_for_file[$unique_file_id % count($servers_for_file)];
  }

Note: if you don't want to create a small module for this function, or if you
      would just like to experiment with this function, you can also enter the
      body of this function at admin/settings/cdn/other — it will work exactly
      the same!
      If you don't know what the "body" of a function is, it's the part
      between the curly brackets:
        function doSomething() {
          BODY
        }
      So, in the case of the cdn_pick_server() function, this is the body that
      you would enter:
        $filename = basename($servers_for_file[0]['url']);
        $unique_file_id = hexdec(substr(md5($filename), 0, 5));
        return $servers_for_file[$unique_file_id % count($servers_for_file)];

Note: cdn3.example.com will serve *all* files because you didn't specify any file types, including the .css, .js and .jpg files that the other domains will serve. You'd have to specify all other extensions that you want to serve from cdn3.example.com if you don't want it to server .css, .js and .jpg files.

pkej’s picture

My bad, I read the README until I got it working (while testing with Yslow), thanks for the heads up.

wim leers’s picture

So you've got it working now? :)

pkej’s picture

I'm sorry Wim, but it doesn't seem to work as expected, I pasted in the code as per your instructions, but the files come from the same alias (cdn4 in my case), none from cdn5 and cdn6.

I'm a bit unsure about what your modulo do, and if that is supposed to select different servers or not, for now it seems that it doesn't, but it might be some caching, either in the browser, my firewall, or the webserver :)

I'll try again tomorrow and check if I get different servers then.

Thanks for the time to follow up on this.

pkej’s picture

Seems to work now, thank you for the help.

wim leers’s picture

What went wrong in #4?

pkej’s picture

It was boost anonymous caching which I didn't flush deeply enough. IUI (Insufficient user intelligence)

wim leers’s picture

Haha :D

Nice one :)

Status: Fixed » Closed (fixed)

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