hevilp
Posts: 64
Joined: Sun Sep 09, 2012 6:13 pm

node.js performance

Thu Jul 02, 2015 5:46 pm

my server runs node.js. I am using the code below to login with username/password from mysql. On my windows-machine its working fine and fast. On the raspberry one post-request needs over 50 seconds. why?

Code: Select all

POST /login 200 57143.232 ms - 172
why does it takes so long? its only a small json response. Its normal on the RPi?

Code: Select all

 connection.query("SELECT * FROM users WHERE username = ?",[username], function(err, rows) {
            if (err) {
            throw err;
            } else {
                    if (!rows.length) {
                    console.log('Unknown User');
                        response.json({
                        success : false
                        });
                    } else {
                        // if the user is found but the password is wrong
                        if (!bcrypt.compareSync(password, rows[0].password)) {
                        //return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.')); // create the loginMessage and save it to session as flashdata
                        console.log('Wrong Password');
                        response.json({
                        success : false
                        });
                        } else {
                            // all is well, return successful user
                            // create a token
                            var token = jwt.sign(username, app.get('superSecret'), {
                             expiresInMinutes: 720 // expires in 24 hours
                            });
                            console.log('Correct');
                            var gr = rows[0].gr;
                            var pos = rows[0].pos;
                            var dir = rows[0].dir;
                            var br = rows[0].br;
                            console.log(dir+br+gr+pos);
                            response.json({
                                              success : 1
                                            , username : username
                                            , dir : dir
                                            , br : br
                                            , gr : gr
                                            , pos : pos
                                            , token : token});
                            //response.redirect('/');
                            response.end();
                            }
                        }                   

                }
    }

Return to “Advanced users”