mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
decaffeinate: Convert loadTest.coffee to JS
This commit is contained in:
parent
e20da38e09
commit
3901fe9cd2
1 changed files with 85 additions and 59 deletions
|
@ -1,71 +1,97 @@
|
|||
request = require "request"
|
||||
Settings = require "settings-sharelatex"
|
||||
async = require("async")
|
||||
fs = require("fs")
|
||||
_ = require("underscore")
|
||||
concurentCompiles = 5
|
||||
totalCompiles = 50
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const request = require("request");
|
||||
const Settings = require("settings-sharelatex");
|
||||
const async = require("async");
|
||||
const fs = require("fs");
|
||||
const _ = require("underscore");
|
||||
const concurentCompiles = 5;
|
||||
const totalCompiles = 50;
|
||||
|
||||
buildUrl = (path) -> "http://#{Settings.internal.clsi.host}:#{Settings.internal.clsi.port}/#{path}"
|
||||
const buildUrl = path => `http://${Settings.internal.clsi.host}:${Settings.internal.clsi.port}/${path}`;
|
||||
|
||||
mainTexContent = fs.readFileSync("./bulk.tex", "utf-8")
|
||||
const mainTexContent = fs.readFileSync("./bulk.tex", "utf-8");
|
||||
|
||||
compileTimes = []
|
||||
failedCount = 0
|
||||
const compileTimes = [];
|
||||
let failedCount = 0;
|
||||
|
||||
getAverageCompileTime = ->
|
||||
totalTime = _.reduce compileTimes, (sum, time)->
|
||||
sum + time
|
||||
, 0
|
||||
return totalTime / compileTimes.length
|
||||
const getAverageCompileTime = function() {
|
||||
const totalTime = _.reduce(compileTimes, (sum, time)=> sum + time
|
||||
, 0);
|
||||
return totalTime / compileTimes.length;
|
||||
};
|
||||
|
||||
makeRequest = (compileNumber, callback)->
|
||||
bulkBodyCount = 7
|
||||
bodyContent = ""
|
||||
while --bulkBodyCount
|
||||
bodyContent = bodyContent+=mainTexContent
|
||||
const makeRequest = function(compileNumber, callback){
|
||||
let bulkBodyCount = 7;
|
||||
let bodyContent = "";
|
||||
while (--bulkBodyCount) {
|
||||
bodyContent = (bodyContent+=mainTexContent);
|
||||
}
|
||||
|
||||
|
||||
startTime = new Date()
|
||||
request.post {
|
||||
url: buildUrl("project/loadcompile-#{compileNumber}/compile")
|
||||
json:
|
||||
compile:
|
||||
resources: [
|
||||
path: "main.tex"
|
||||
content: """
|
||||
\\documentclass{article}
|
||||
\\begin{document}
|
||||
#{bodyContent}
|
||||
\\end{document}
|
||||
"""
|
||||
const startTime = new Date();
|
||||
return request.post({
|
||||
url: buildUrl(`project/loadcompile-${compileNumber}/compile`),
|
||||
json: {
|
||||
compile: {
|
||||
resources: [{
|
||||
path: "main.tex",
|
||||
content: `\
|
||||
\\documentclass{article}
|
||||
\\begin{document}
|
||||
${bodyContent}
|
||||
\\end{document}\
|
||||
`
|
||||
}
|
||||
]
|
||||
}, (err, response, body)->
|
||||
if response.statusCode != 200
|
||||
failedCount++
|
||||
return callback("compile #{compileNumber} failed")
|
||||
if err?
|
||||
failedCount++
|
||||
return callback("failed")
|
||||
totalTime = new Date() - startTime
|
||||
console.log totalTime+"ms"
|
||||
compileTimes.push(totalTime)
|
||||
callback(err)
|
||||
}
|
||||
}
|
||||
}, function(err, response, body){
|
||||
if (response.statusCode !== 200) {
|
||||
failedCount++;
|
||||
return callback(`compile ${compileNumber} failed`);
|
||||
}
|
||||
if (err != null) {
|
||||
failedCount++;
|
||||
return callback("failed");
|
||||
}
|
||||
const totalTime = new Date() - startTime;
|
||||
console.log(totalTime+"ms");
|
||||
compileTimes.push(totalTime);
|
||||
return callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
jobs = _.map [1..totalCompiles], (i)->
|
||||
return (cb)->
|
||||
makeRequest(i, cb)
|
||||
const jobs = _.map(__range__(1, totalCompiles, true), i=>
|
||||
cb=> makeRequest(i, cb)
|
||||
);
|
||||
|
||||
startTime = new Date()
|
||||
async.parallelLimit jobs, concurentCompiles, (err)->
|
||||
if err?
|
||||
console.error err
|
||||
console.log("total time taken = #{(new Date() - startTime)/1000}s")
|
||||
console.log("total compiles = #{totalCompiles}")
|
||||
console.log("concurent compiles = #{concurentCompiles}")
|
||||
console.log("average time = #{getAverageCompileTime()/1000}s")
|
||||
console.log("max time = #{_.max(compileTimes)/1000}s")
|
||||
console.log("min time = #{_.min(compileTimes)/1000}s")
|
||||
console.log("total failures = #{failedCount}")
|
||||
const startTime = new Date();
|
||||
async.parallelLimit(jobs, concurentCompiles, function(err){
|
||||
if (err != null) {
|
||||
console.error(err);
|
||||
}
|
||||
console.log(`total time taken = ${(new Date() - startTime)/1000}s`);
|
||||
console.log(`total compiles = ${totalCompiles}`);
|
||||
console.log(`concurent compiles = ${concurentCompiles}`);
|
||||
console.log(`average time = ${getAverageCompileTime()/1000}s`);
|
||||
console.log(`max time = ${_.max(compileTimes)/1000}s`);
|
||||
console.log(`min time = ${_.min(compileTimes)/1000}s`);
|
||||
return console.log(`total failures = ${failedCount}`);
|
||||
});
|
||||
|
||||
|
||||
function __range__(left, right, inclusive) {
|
||||
let range = [];
|
||||
let ascending = left < right;
|
||||
let end = !inclusive ? right : ascending ? right + 1 : right - 1;
|
||||
for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) {
|
||||
range.push(i);
|
||||
}
|
||||
return range;
|
||||
}
|
Loading…
Reference in a new issue