Skip to content

Commit

Permalink
cache improvements / fix in path reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenguira committed Oct 17, 2020
1 parent ab66fe7 commit fcdcb26
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DB/MYSQL/startMYSQL.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function startContainer {
echo "Starting new mysql80 container"

docker run --name=mysql80 \
--publish $NETFACE:3306:$NETPORT \
--publish $NETFACE:$NETPORT:3306 \
-e MYSQL_ROOT_PASSWORD=$rootPassword \
-e MYSQL_ROOT_HOST=172.17.0.1 \
-v $DBPATH:/var/lib/mysql \
Expand Down
8 changes: 6 additions & 2 deletions modules/api-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ module.exports = {
finalQueryObj = parseURLEncParams(reqInfos.query);
} else {

if (Object.keys(bodyParserTool).includes(contentType.split(';')[0] )) {
if (contentType != null && Object.keys(bodyParserTool).includes(contentType.split(';')[0] )) {
finalQueryObj = bodyParserTool[contentType.split(';')[0]](reqInfos.body);
}
else if (contentType.indexOf("multipart/form-data") > -1) {
else if (contentType != null && contentType.indexOf("multipart/form-data") > -1) {
var event = {"httpMethod": reqInfos.method.toUpperCase()};
event[reqInfos.method.toUpperCase()] = {};

Expand Down Expand Up @@ -670,9 +670,13 @@ async function ExecuteFunction(apiEndpoint, curFunction, functionHandlerFunction

//console.log(JSON.stringify(response))
//console.log(response.content || response.body || response);

//already done globally in router.js
/*
const nanoSeconds = process.hrtime(beginPipeline).reduce((sec, nano) => sec * 1e9 + nano);
var durationMS = (nanoSeconds/1000000).toFixed(2);
headers["durationMS"] = durationMS;
*/

if (typeof response == "object") {
resolve({
Expand Down
20 changes: 14 additions & 6 deletions modules/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
_serverConfig = serverConfig;
}

//console.log(serverConfig.outputcache)
if ( serverConfig.outputcache ){
lru = HLRU(500);
}
Expand Down Expand Up @@ -91,7 +92,7 @@ module.exports = {

res.writeStatus("" + (result.status || 200));
for (var key in result.headers) {
res.writeHeader(key, result.headers[key]);
res.writeHeader(key, result.headers[key] + "");
}

if (result.content != null) {
Expand Down Expand Up @@ -218,7 +219,11 @@ module.exports = {
{
//var cacheContent = memory.get(cacheKey, "ResponseCache");
var cacheContent = lru.get(cacheKey);
if (cacheContent != null) {
//var cacheContent = sharedmem.getString(cacheKey, "RESPONSECACHE");

if (cacheContent != null && cacheContent != "") {

//cacheContent = JSON.parse(cacheContent);

if ( serverConfig.debug){
console.log("Serving from cache:" + cacheKey) ;
Expand All @@ -228,12 +233,14 @@ module.exports = {
var totalBytesSent = 0;

var processResult = cacheContent;
processResult.headers["core-cache"] = 1;

res.writeStatus("" + (processResult.status || 200));
for (var key in processResult.headers) {
res.writeHeader(key, processResult.headers[key]);
res.writeHeader(key, processResult.headers[key] + "");
totalBytesSent += key.length + processResult.headers[key].length;
}
res.writeHeader("durationMS", "0ms");
res.writeHeader("processing", "<1ms");

if (processResult.content != null) {

Expand Down Expand Up @@ -317,8 +324,9 @@ module.exports = {
//console.log(processResult);

//memory.set(cacheKey, processResult, "ResponseCache");
//Disable LRU completely by commenting next line
//sharedmem.setString(cacheKey, JSON.stringify(processResult), "RESPONSECACHE");;
lru.set(cacheKey, processResult);

}
else{
//console.log( "test: " + processResult.error);
Expand Down Expand Up @@ -372,7 +380,7 @@ module.exports = {
}

//add processingTime header
res.writeHeader("durationMS", parseInt(nanoSecondsPipeline/1000000) + "ms");
res.writeHeader("processing", (nanoSecondsPipeline/1000000).toFixed(2) + "ms");

//Add HSTS to reach A+ on SSL Labs test
if ( appConfig.HSTS == true ){
Expand Down
2 changes: 1 addition & 1 deletion modules/static-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
process: (appConfig, reqInfos, res, req, memory, serverConfig, app) => {

var rootFolder = tools.safeJoinPath(appConfig.root, appConfig.publicFolder);
var curURL = reqInfos.url.split('?')[0];
var curURL = decodeURIComponent(reqInfos.url.split('?')[0]);

if (appConfig.AWS == null || appConfig.TypeFS != "S3" ) {
if (!fileMonitorStarted && serverConfig.watch == true) {
Expand Down

0 comments on commit fcdcb26

Please sign in to comment.