Photon: Where is my Bandwidth Going?

I’ve recently been investigating some curious behaviour that has been going on on a server I administer. This is a VM hosted with  Mythic Beasts, and it hosts a variety of sites, several of which use WordPress (like this!) – the specific problem I’ve seen is a large bandwidth increase over a couple of months. The following chart demonstrates:

Yearly Bandwidth Usage Chart

Now, the usage levels are still well inside my allowed totals, but I decided to have a look – I know a couple of the sites are reasonably popular ones, and they could have had a surge in activity, but the figures are more interesting.

As it turned out, after totting up totals by vhost, the vast majority of the bandwidth was going on one site. In a 2 week period, 95% of the bandwidth was serving one vhost at about 6GB a day. More curiously, this vhost (running a fully patched WP instance) has of the order of 500 hits a day over this period.  While there are some wonderful images on this site, and several per post, there’s should be nowhere near this amount of data. What makes it more confusing is that Jetpack was installed, and had Photon enabled.

Photon is the free service from WordPress that allows serving of images from a content delivery network (CDN), which is designed to take load (really bandwidth as images are simple to serve) away from the source server. Having done a little digging in the logs, it turns out there were entries like this:


192.0.86.129 - - [01/Nov/2015:03:40:11 +0000] 'GET /wp-content/uploads/2014/11/IMG_1667.jpg HTTP/1.1' 200 500600 '-' 'Photon/1.0'
192.0.86.185 - - [01/Nov/2015:03:40:17 +0000] 'GET /wp-content/uploads/2014/11/IMG_1667.jpg HTTP/1.1' 200 500600 '-' 'Photon/1.0'
192.0.86.162 - - [01/Nov/2015:03:40:20 +0000] 'GET /wp-content/uploads/2014/11/IMG_1667.jpg HTTP/1.1' 200 500600 '-' 'Photon/1.0'

<snip another 140 similar lines…>

192.0.86.143 - - [01/Nov/2015:03:47:35 +0000] 'GET /wp-content/uploads/2014/11/IMG_1667.jpg HTTP/1.1' 200 500600 '-' 'Photon/1.0'
192.0.86.125 - - [01/Nov/2015:03:47:38 +0000] 'GET /wp-content/uploads/2014/11/IMG_1667.jpg HTTP/1.1' 200 500600 '-' 'Photon/1.0'

So, 145 requests for the same file within 7 minutes – what on earth? CDN are supposed to cache to avoid rerequesting data like this. More confusing is that there just weren’t this number of page requests in this period – in fact there were only 18 requests for feeds or posts… Across 2 weeks in this single vhost, total traffic was 82GB, with 73GB of images being served to Photon alone – and there’s only 2GB of data on disc for the vhost, including code!

So, after raising a support call with Jetpack (and have to say the support staff were helpful and responsive here), I got a little way to working out what it was doing.

When Photon gets a request for a file it doesn’t have, it requests the full size image from the source blog, which is fine. Photon also does resizing/optimization of images when the image requested has relevant GET parameters (eg w, h, resize, etc) – here it does the same thing in that it re-requests the full size image and resizes it.

Though confirmed that this is the expected behaviour by the Devs, I think this is a design flaw. Photon already stores the images forever (if you want to change an image, you must change the filename – that’s documented) and it would make sense to retain the original and use this for resizing appropriately when it needs to. Even as is, you’d expect the images in use to get cached up and then be served from CDN so you should reasonably quickly build up all the sizes you need in cache.

So what about the 145 requests? Well, after being sent the logs by Jetpack support, it’s clear that there are a load of individual requests for the same image with different sizes, eg:

i2.wp.com - - - - [01/Nov/2015:03:40:39 +0000] GET /XXX/wp-content/uploads/2014/11/IMG_1667.jpg?zoom=2&resize=523%2C512 HTTP/1.1 <REFERER>
i2.wp.com - - - - [01/Nov/2015:03:40:42 +0000] GET /XXX/wp-content/uploads/2014/11/IMG_1667.jpg?zoom=2&resize=519%2C508 HTTP/1.1 <REFERER>
i2.wp.com - - - - [01/Nov/2015:03:40:45 +0000] GET /XXX/wp-content/uploads/2014/11/IMG_1667.jpg?zoom=2&resize=515%2C504 HTTP/1.1 <REFERER></code>

And so on, all the way down to a resize request with size 61 x 50px… So, this is expected behaviour, but (despite the referrer looking right) these image requests don’t appear to be from pages that are WP generated. I’m not sure really how and where these are being generated – are they bots, apps, scrapes, feeds? Hard to know, as I don’t have the full details, but it’s hugely inefficient once Photon starts dealing with those requests. This is by no means the worst – from the last 2 weeks:

# zgrep "Photon" site-access.log.* | grep "/wp-content/uploads/2015/08/imagename.jpg" | wc -l

5484

Ouch.

So, my current approach is to stop serving images in this way for this site – I can’t block it entirely, since you need Photon to serve image grids, etc, but after a day it looks to be going in the right direction (see the flat, non peaky graph in the last day):

Weekly Bandwidth Usage
I’d be interested if anyone else has seen similar behaviour – please leave comments!

Disappointingly, Jetpack say there’s no plans to change this behaviour, so for me this rules out its use on this size of site. It clearly does save bandwidth for normal requests, but it’s had a negative impact here – I could see it working for much larger image heavy sites, even with the frequent re-requests, but it’s just not working here.

 

EDIT 18-Nov-2015:

Point proved? (There was a popular post today which accounts for the late blip!)

Bandwidth - 18/11/2015

 

 

M101 – Pinwheel Galaxy

Field centered at: RA: 14h 03m 12.6s, Dec: +54° 21′ 16.7″
Up: 178 E of N.

(plate solve from nova.astrometry.net)

The Pinwheel Galaxy, M101 is located in Ursa Major, and I found this a surprisingly tricky object to image – it has low surface brightness, with a lot of faint outlying regions. I also appeared to have some small issues with the flat fielding process here – there are a couple of very large dust bunnies in the raw data that haven’t quite been subtracted away and there’s a touch of clipping to deal with this. Add to this some faint colour gradients (attempted to sort out gradients!) and a couple of bright stars in the field and it became something very tricky to try and get right (and I’m still not 100% convinced that it’s truly there yet…).

The fainter galaxy to the right (east) of M101 is NGC5477, which is a dwarf galaxy at about the same distance (~20MLy). There are lots of fainter objects in the image as well: the brighter galaxy to the upper left of M101 for example is MCG+09-23-25, and there are also loads of other faint galaxies, galaxy groups and QSOs lurking in there. Using a solved fits file in Aladin is very instructive here!

I used fairly long exposure lengths (I was using the FLT110 at f7 here, a shorter focal length would be a major bonus in truth – at f4-5 this would be a much deeper image!). Exposure details are as follows:

WO FLT110 @ f7 on Losmandy Titan, ST2000XM cooled to -20C (images on 18 & 19-Apr-2015)
L: 4.5hrs (1×1)
R: 70min (2×2 binned)
G: 48min (2×2 binned)
B: 48min (2×2 binned)

The Luminance for the image was processed using a Lucy-Richardson deconvolution (3 iterations) using CCDSharp.

M101 - Pinwheel Galaxy in UMa (Luminance)

 

M101 - Pinwheel Galaxy in UMa (LLRGB)

Eclipse Calculations using Python

On 20th March there is a deep partial solar eclipse over the  UK which is total over the Faroe Islands and Svalbard. I set about trying to determine the time of maximum eclipse, and percentage eclipsed at a given location.

I used the pyephem module which is a Python implementation of the numerical routines that are behind the excellent Xephem. The module will allow a user to calculate the positions of astronomical objects (eg Sun, Moon, etc) from a given location at a given time. Using the positions of these objects it’s possible to determine the separation of the centres of these objects.

To work out the percentage eclipse at that time, I used the formula on the Wolfram Mathworld page on “Lunes” (author: Weisstein, Eric W). A “Lune” is the “plane figure bounded by two circular arcs of unequal radii, i.e., a crescent.” which exactly describes the visible surface of the sun during an eclipse.

With the area of the lune calculated, it’s trivial to work out the percent eclipse at that time – and by looping over time, it’s possible to get a list of lists to search for a maximum.

The code can be downloaded using this link: eclipse_percent.py

The result I get (using the location of the Science Oxford setup on 20th March – the SBS in Oxford, UK) is as follows:

Max Eclipse occurs at: 2015-03-20  09:30:11 GMT
Max percentage eclipse: 85.86
First contact: 08:24:21 GMT
Last contact: 10:40:04 GMT

All we need now is some decent weather…

The featured image here is an H-Alpha filtered frame taken by me on 3rd Oct 2005 from Denia, Spain, during the early phases of an annular eclipse.

M35 & NGC 2158

Field centred at: RA: 6h 08m 25.2s, Dec: +24° 15′ 06.2″
(plate solve from astrometry.net)

M35 and NGC2158 are a pair of open clusters which, similarly to the more famous h and X Persei, are viewed nearly on the same line of sight from Earth. M35 is somewhat younger (as evidenced by the predominantly blue stars as compared to the older yellow stars in NGC2158), and a lot closer to us – while NGC2158 is more compact with more stars in the same volume.

M35 & NGC2158 in Gemini
M35 & NGC2158

This exposure was taken on the 8th February 2015 but was somewhat shortened by fog rapidly rolling in, and hence the rather short total exposure:

ST2000XM, FLT110, Losmandy Titan
LRGB: 20:9:9:9 each in 1min subs.

C/2014 Q2 (Lovejoy) – 8th Feb 2015

Field centred at: RA 02:00:07, Dec +45:10:35.
Field size: 51.4 x 38.9arcmin; Field rotation: up is 179.9° E of N
(plate solve by local astrometry.net instance)

Comet Lovejoy was discovered in summer 2014 by Terry Lovejoy and is a long period comet and had a period of about 11000 years (now reduced to about 8000 years after this approach to the sun.

C2014-Q2-20150208.jpg
Comet Lovejoy (C/2014 Q2)

 

C2014-Q2-20150208-neg-tail.jpg
C/2014 Q2 (Lovejoy) – in negative, showing tail detail

 

Images were taken on the evening of the 8th Feb 2015 using an ST2000XM  through a William Optics FLT110 on Losmandy Titan. 26 each of L, R,G,B filtered frames, each taken in that sequence (so each frame of each filter starting about 5 minutes apart).

Processing of the colour image with the comet “frozen” against the stars followed Bernhard Hubl’s method of processing the comet. The negative image which enhances the tail was produced by a median combine of the data while aligned on the comet itself rather than the background stars (the comet was moving at about 2arcsec/min at the time).