Created
September 12, 2011 00:45
-
-
Save sergiolopes/1210374 to your computer and use it in GitHub Desktop.
Bastidores das análises dos Sites dos participantes do QCon SP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Algumas pessoas me perguntaram como fiz a análise dos Sites do pessoal que foi no QCon. Sim, eu analisei | |
o Site de todo mundo, um por um, e fiz as médias. Mas obviamente, nada manual, então lá vai como fiz: | |
1) Peguei o e-mail de todo mundo cadastrado e extraí o domínio. Tirei os e-mails de webmails genéricos | |
(gmail, hotmail etc) e separei os domínios das empresas. Salvei tudo num urls.txt (no total deram umas | |
100 URLs únicas). | |
2) Submeti todos os domínios (prefixados por http://www) pro WebPageTest.org. Para isso, fiz um programinha | |
Java usando Selenium2 (código abaixo no gist) | |
3) O programa anterior cospe os test_ids gerados pelo WebPageTest para cada teste. Esperei uns minutos e | |
baixei os resultados (em .csv e .har) usando outro programinha Java (código abaixo no gist). | |
4) Peguei os CSV e joguei num Google Spreadsheets pra ordenar, tirar médias de algumas métricas etc. | |
PS. O WebPageTest tem uma API REST mas você precisa registrar um key o que não é muito fácil (ou rodar | |
sua instância própria no EC2). Usando o Selenium consegui submeter os testes sem problemas usando a | |
interface normal do Site mesmo :) | |
PS2: Nao vou divulgar os endereços individuais nem estatisticas de sites especificos. Mas se alguem | |
quiser saber mais algum numero de media, so perguntar | |
----- | |
Slides da apresentação com resultado dos estudos: | |
www.slideshare.net/caelumdev/qcon-2011-por-uma-web-mais-rpida-tcnicas-de-otimizao-de-sites |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "scriptizao" pra baixar os resultados depois de executados | |
public class DownloadResults { | |
public static void main(String[] args) throws FileNotFoundException { | |
Scanner results = new Scanner(new File("test-ids.txt")); | |
while (results.hasNextLine()) { | |
String[] result = results.nextLine().split("\\s+"); | |
String testId = result[0]; | |
String domain = result[1]; | |
System.out.print("Downloading results for " + domain); | |
String pageDataUri = "http://www.webpagetest.org/result/" + testId + "/" + testId + "_www." + domain + "_page_data.csv"; | |
String pageDataOutput = "results/page_data/" + domain + ".csv"; | |
try { | |
download(pageDataUri, pageDataOutput); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
String requestsUri = "http://www.webpagetest.org/result/" + testId + "/" + testId + "_www." + domain + "_requests.csv"; | |
String requestsOutput = "results/requests/" + domain + ".csv"; | |
try { | |
download(requestsUri, requestsOutput); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
String harUri = "http://www.webpagetest.org/export.php?test=" + testId; | |
String harOutput = "results/har/" + domain + ".json"; | |
try { | |
download(harUri, harOutput); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
System.out.println(" [COMPLETED]"); | |
} | |
results.close(); | |
} | |
private static void download(String uri, String output) | |
throws MalformedURLException, IOException, FileNotFoundException { | |
URL url = new URL(uri); | |
ReadableByteChannel rbc = Channels.newChannel(url.openStream()); | |
FileOutputStream fos = new FileOutputStream(output); | |
fos.getChannel().transferFrom(rbc, 0, 1 << 24); | |
fos.close(); | |
rbc.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "scriptizão" feio pra submeter os testes no WebPageTest.org | |
// pra rodar, tenha os JARs do Selenium2 no classpath | |
public class PostTests { | |
static FirefoxDriver driver = new FirefoxDriver(); | |
public static void main(String[] args) throws FileNotFoundException { | |
PrintWriter tests = new PrintWriter("test-ids.txt"); | |
Scanner domains = new Scanner(new File("urls.txt")); | |
while (domains.hasNextLine()) { | |
try { | |
String domain = domains.nextLine(); | |
String uri = "http://www." + domain + "/"; | |
System.out.print("Testing: " + uri); | |
String testId = submitTestTo(uri); | |
System.out.println(" [COMPLETED]"); | |
tests.println(testId + " " + domain); | |
tests.flush(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
continue; | |
} | |
} | |
domains.close(); | |
tests.close(); | |
driver.quit(); | |
} | |
private static String submitTestTo(String uri) { | |
driver.navigate().to("http://www.webpagetest.org/"); | |
WebElement uriField = driver.findElement(By.name("url")); | |
uriField.clear(); | |
uriField.sendKeys(uri); | |
driver.findElement(By.name("submit")).click(); | |
(new WebDriverWait(driver, 15)).until(new ExpectedCondition<Boolean>() { | |
public Boolean apply(WebDriver d) { | |
return d.getCurrentUrl().startsWith("http://www.webpagetest.org/result/"); | |
} | |
}); | |
String testUrl = driver.getCurrentUrl(); | |
String testId = testUrl.split("/")[4]; | |
return testId; | |
} | |
} |
Muito legal! cade o post com as referências que você falou que iria publicar?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fiz um teste naquelas lojas com home de 8 MB com o Chrome (Incognito mode para não cachear), e elas deram pouco mais de 2 MB. Talvez tenham trocado o site deles de lá pra cá, ou seja um bug no Web Page Test.