Server Products
Data Center Products including boards, integrated systems, Intel® Xeon® Processors, RAID Storage, and Intel® Xeon® Processors
4762 Discussions

My node JS web-server is too slow ??

Hhout
Novice
1,823 Views

My webserver is running very slow

here is my code!

 

/**** indicate if Relays are on or off ****/

var relay_1_status = "off";

var relay_2_status = "off";

var relay_3_status = "off";

var relay_4_status = "off";

var system = require('child_process').exec;

var mraa = require('mraa');

/*

* About controlling galileo with a webpage

*/

function startServer()

{

console.log("Loading..");

var R1 = new mraa.Gpio(2);

var R2 = new mraa.Gpio(3);

var R3 = new mraa.Gpio(4);

var R4 = new mraa.Gpio(5);

R1.dir(mraa.DIR_OUT);

R2.dir(mraa.DIR_OUT);

R3.dir(mraa.DIR_OUT);

R4.dir(mraa.DIR_OUT);

console.log("Starting web controller...");

var http = require('http');

http.createServer(function (req, res) {

function respond() {

res.writeHead(200, { "Content-Type": "text/html" });

res.write("<!DOCTYPE html>");

res.write("OstaLab Final Project");

res.write("

Switches Status :

");

res.write(relay_1_status);

res.write(relay_2_status);

res.write(relay_3_status);

res.write(relay_4_status);

res.write("

Control your sweet home ^_^ :

");

res.write("

");

res.write("

");

res.write("

");

res.write("

");

res.write("

");

res.write("

");

res.write("

");

res.write("

");

res.write("");

res.end();

}

console.log("Request: " + req.url);

// Control L Switch 1

if(req.url === "/S1On") {

R1.write(0);

relay_1_status = "on";

console.log("pin 2 on");

}

if(req.url === "/S1Off") {

R1.write(1);

relay_1_status = "off";

console.log("pin 2 off");

}

// Control L Swtich 2

if(req.url === "/S2On") {

R2.write(0);

relay_2_status = "on";

console.log("pin 3 on");

}

if(req.url === "/S2Off") {

R2.write(1);

relay_2_status = "off";

console.log("pin 3 off");

}

// Control L Swtich 3

if(req.url === "/S3On") {

R3.write(0);

relay_3_status = "on";

console.log("pin 4 on");

}

if(req.url === "/S3Off") {

R3.write(1);

relay_3_status = "off";

console.log("pin 4 off");

}

// Control L Swtich 4

if(req.url === "/S4On") {

R4.write(0);

relay_4_status = "on";

console.log("pin 5 on");

}

if(req.url === "/S4Off") {

R4.write(1);

relay_4_status = "off";

console.log("pin 5 off");

}

respond();

}).listen(1337);

console.log('Server running at http://your_board_IP:1337/'); http://your_board_IP:1337/');

}

/*

* What we want to run

*/

console.log("Starting server");

startServer();

Any Suggestions ??

0 Kudos
4 Replies
Carlos_M_Intel
Employee
611 Views

Hi Hathout,

Do you have an estimated time for the delays in your application?

What is the output of running uname –a?

Are you just running this application in your board?

Are you sure this is not an issue with the network itself?

I suggest you to debug your code to check the delays you are getting between the requests to the server. You can also try to edit your code in order to be modular and not a sequence

Regards,

Charlie

Hhout
Novice
611 Views
Carlos_M_Intel
Employee
611 Views

Hi Hathout,

Do you have updates in this?

Have you been able to debug your code?

Regards,

Charlie

0 Kudos
Reply