Giter Club home page Giter Club logo

Comments (6)

patriksimek avatar patriksimek commented on May 24, 2024

This isn't a normal behaviour. Could you please describe you environment?

from node-mssql.

RidiQirici avatar RidiQirici commented on May 24, 2024

I am using a core i5 3GHZ with 8GB RAM computer. The code is written in visual studio 2013 and using SQL SERVER 2008 R2, using visual studion tool for node js.
Here is the structure of my code:

var sql = require('mssql');
var async = require("async");

insertSales = function (salesList, salesIDPrefix, res) {
    async.map(salesList.headSales,
        function (headItem, callbackMap) {
            async.filter(salesList.bodySales,
                function (item, callbackFilter) {

                }.bind({}),
                function (bodyItemOfHead) {
                    createConnection(insertSalesCon, callback, { headSales: headItem, bodySales: bodyItemOfHead, salesIDPrefix: salesIDPrefix })
                })
        }.bind({ salesIDPrefix: salesIDPrefix }),
        function (err, resultInsertSales) {

        });
};

createConnection = function (method, callbackFunction, args) {
    // console.time("conn");
    var connection = new sql.Connection(configDb, function (err) {
        // console.timeEnd("conn");
        if (err) {

        };
        method(connection, args, callbackFunc);
    });
};

insertSalesCon = function (connection, args, callback) {
    var transaction = new sql.Transaction(connection);
    // console.time("begin tran");
    transaction.begin(function (err) {
        // console.timeEnd("begin tran");
        if (err) {
        };
        insertHeadSales(transaction, args, callback);
    });
};

function insertHeadSales(transaction, args, callback) {
    var request = new sql.Request(transaction);
    request.output('AAAAA', sql.BigInt);
    request.input('BBBBB', sql.VarChar, args.salesIDPrefix + args.headSales['CCCCC']);
    ......
    // console.time("sp1");
    request.execute('store_procedure1',
        function (err, recordsets, returnValue) {
            // console.timeEnd("sp1");
            if (err) {

            }
            var idHeadSales = request.parameters.AAAAA.value;
            async.map(args.bodySales, function (bdSales, callbackMapi) {
                insertBodySales(bdSales, idHeadSales, transaction, callbackMapi);
            }, function (err, result) {
                if (err) {
                    // console.time("rollback tran");
                    transaction.rollback(function (err, recordset) {
                        // console.timeEnd("rollback tran");
                    });
                }
                // console.time("commit tran");
                transaction.commit(function (err, recordset) {
                    // console.timeEnd("commit tran");
                    if (err) {
                    }
                    callback(null, { inserted: true, idHEAD: args.headSales['CCCCC'] });
                });
            })
        });
};

function insertBodySales(bdSales, idHeadSales, transaction, callbackMapi) {
    var request = new sql.Request(transaction);
    request.input('DDDDDD', sql.VARCHAR, idHeadSales);
    .......
    // console.time("sp2");
    request.execute('store_procedure2', function (err, recordsets, returnValue) {
        // console.timeEnd("sp2");
        if (err) {
            console.log("ERROR: gjate shkrimit te trupiShitjes" + err.message);
            // console.time("rollback tran 2");
            transaction.rollback(function (err, recordset) {
                // console.timeEnd("rollback tran 2");
            });
            return;
        }
        callbackMapi(null, true);
    });
};

from node-mssql.

patriksimek avatar patriksimek commented on May 24, 2024

I have made some comments to the code you posted. Could you please try to run it with uncommented lines? It should help us to find a problem part.

from node-mssql.

RidiQirici avatar RidiQirici commented on May 24, 2024

The result is much longer than the result I am sending.

[03:04:15:22:25.108] sp2: 64395ms
[03:04:15:22:25.108] sp2: 64395ms
[03:04:15:22:25.109] sp2: 64396ms
[03:04:15:22:25.111] sp2: 64398ms
[03:04:15:22:25.112] sp2: 64399ms
[03:04:15:22:25.113] sp2: 64400ms
[03:04:15:22:25.115] sp2: 64402ms
[03:04:15:22:25.116] sp2: 64403ms
[03:04:15:22:25.117] sp2: 64404ms
[03:04:15:22:25.119] sp2: 64406ms
[03:04:15:22:25.120] sp2: 64407ms
[03:04:15:22:25.121] sp2: 64408ms
[03:04:15:22:25.123] sp2: 64410ms
[03:04:15:22:25.124] sp2: 64411ms
[03:04:15:22:25.125] sp2: 64412ms
[03:04:15:22:25.126] sp2: 64413ms
[03:04:15:22:25.127] sp2: 64414ms
[03:04:15:22:25.127] sp2: 64414ms
[03:04:15:22:25.128] sp2: 64415ms
[03:04:15:22:25.129] sp2: 64416ms
[03:04:15:22:25.129] sp2: 64416ms
[03:04:15:22:25.131] sp2: 64418ms
[03:04:15:22:25.132] sp2: 64419ms
[03:04:15:22:25.132] sp2: 64419ms
[03:04:15:22:25.133] sp2: 64420ms
[03:04:15:22:25.134] sp2: 64421ms
[03:04:15:22:25.134] sp2: 64421ms
[03:04:15:22:25.135] sp2: 64422ms
[03:04:15:22:25.136] sp2: 64423ms
[03:04:15:22:25.136] sp2: 64423ms
[03:04:15:22:25.137] sp2: 64424ms
[03:04:15:22:25.138] sp2: 64425ms
[03:04:15:22:25.138] sp2: 64425ms
[03:04:15:22:25.139] sp2: 64426ms
[03:04:15:22:25.140] sp2: 64427ms
[03:04:15:22:25.140] sp2: 64427ms
[03:04:15:22:25.141] sp2: 64428ms
[03:04:15:22:25.142] sp2: 64429ms
[03:04:15:22:25.143] sp2: 64430ms
[03:04:15:22:25.152] sp2: 64439ms
[03:04:15:22:25.152] sp2: 64439ms
[03:04:15:22:25.163] sp2: 64450ms
[03:04:15:22:25.164] sp2: 64451ms
[03:04:15:22:25.165] sp2: 64452ms
[03:04:15:22:25.166] sp2: 64453ms
[03:04:15:22:25.167] sp2: 64454ms
[03:04:15:22:25.168] sp2: 64455ms
[03:04:15:22:25.170] sp2: 64457ms
[03:04:15:22:25.171] sp2: 64458ms
[03:04:15:22:25.172] sp2: 64459ms
[03:04:15:22:25.174] sp2: 64461ms
[03:04:15:22:25.175] sp2: 64462ms
[03:04:15:22:25.176] sp2: 64463ms
[03:04:15:22:25.177] sp2: 64464ms
[03:04:15:22:25.177] sp2: 64464ms
[03:04:15:22:25.178] sp2: 64465ms
[03:04:15:22:25.179] sp2: 64466ms
[03:04:15:22:25.179] sp2: 64466ms
[03:04:15:22:25.180] sp2: 64467ms
[03:04:15:22:25.181] sp2: 64468ms
[03:04:15:22:25.182] sp2: 64469ms
[03:04:15:22:25.183] sp2: 64470ms
[03:04:15:22:25.184] sp2: 64471ms
[03:04:15:22:25.186] sp2: 64473ms
[03:04:15:22:25.187] sp2: 64474ms
[03:04:15:22:25.188] sp2: 64475ms
[03:04:15:22:25.190] sp2: 64477ms
[03:04:15:22:25.191] sp2: 64478ms
[03:04:15:22:25.192] sp2: 64479ms
[03:04:15:22:25.194] sp2: 64481ms
[03:04:15:22:25.195] sp2: 64482ms
[03:04:15:22:25.196] sp2: 64483ms
[03:04:15:22:25.198] sp2: 64485ms
[03:04:15:22:25.199] sp2: 64486ms
[03:04:15:22:25.200] sp2: 64487ms
[03:04:15:22:25.202] sp2: 64489ms
[03:04:15:22:25.203] sp2: 64490ms
[03:04:15:22:25.204] sp2: 64491ms
[03:04:15:22:25.205] sp2: 64492ms
[03:04:15:22:25.207] sp2: 64494ms
[03:04:15:22:25.208] sp2: 64495ms
[03:04:15:22:25.209] sp2: 64496ms
[03:04:15:22:25.211] sp2: 64498ms
[03:04:15:22:25.212] sp2: 64499ms
[03:04:15:22:25.212] sp2: 64499ms
[03:04:15:22:25.214] sp2: 64501ms
[03:04:15:22:25.215] sp2: 64502ms
[03:04:15:22:25.215] sp2: 64502ms
[03:04:15:22:25.216] sp2: 64503ms
[03:04:15:22:25.217] sp2: 64504ms
[03:04:15:22:25.218] sp2: 64505ms
[03:04:15:22:25.219] sp2: 64506ms
[03:04:15:22:25.219] sp2: 64506ms
[03:04:15:22:25.220] sp2: 64507ms
[03:04:15:22:25.222] sp2: 64509ms
[03:04:15:22:25.223] sp2: 64510ms
[03:04:15:22:25.224] sp2: 64511ms
[03:04:15:22:25.225] sp2: 64512ms
[03:04:15:22:25.227] sp2: 64514ms
[03:04:15:22:25.228] sp2: 64515ms
[03:04:15:22:25.229] sp2: 64516ms
[03:04:15:22:25.231] sp2: 64518ms
[03:04:15:22:25.232] sp2: 64519ms
[03:04:15:22:25.233] sp2: 64520ms
[03:04:15:22:25.235] sp2: 64522ms
[03:04:15:22:25.236] sp2: 64523ms
[03:04:15:22:25.237] sp2: 64524ms
[03:04:15:22:25.237] sp2: 64524ms
[03:04:15:22:25.238] sp2: 64525ms
[03:04:15:22:25.239] sp2: 64526ms
[03:04:15:22:25.241] sp2: 64528ms
[03:04:15:22:25.242] sp2: 64529ms
[03:04:15:22:25.243] sp2: 64530ms
[03:04:15:22:25.243] sp2: 64530ms
[03:04:15:22:25.244] sp2: 64531ms
[03:04:15:22:25.245] sp2: 64532ms
[03:04:15:22:25.246] sp2: 64533ms
[03:04:15:22:25.247] sp2: 64534ms
[03:04:15:22:25.248] sp2: 64535ms
[03:04:15:22:25.249] sp2: 64536ms
[03:04:15:22:25.250] sp2: 64537ms
[03:04:15:22:25.250] sp2: 64537ms
[03:04:15:22:25.251] sp2: 64538ms
[03:04:15:22:25.252] sp2: 64539ms
[03:04:15:22:25.253] sp2: 64540ms
[03:04:15:22:25.254] sp2: 64541ms
[03:04:15:22:25.255] sp2: 64542ms
[03:04:15:22:25.256] sp2: 64543ms
[03:04:15:22:25.256] sp2: 64543ms
[03:04:15:22:25.257] sp2: 64544ms
[03:04:15:22:25.258] sp2: 64545ms
[03:04:15:22:25.259] sp2: 64546ms
[03:04:15:22:25.261] sp2: 64548ms
[03:04:15:22:25.261] commit tran: 11ms
[03:04:15:22:25.262] sp2: 64549ms
[03:04:15:22:25.264] sp2: 64551ms
[03:04:15:22:25.265] sp2: 64552ms
[03:04:15:22:25.268] sp2: 64555ms
[03:04:15:22:25.269] sp2: 64556ms
[03:04:15:22:25.270] sp2: 64557ms
[03:04:15:22:25.271] sp2: 64558ms
[03:04:15:22:25.272] sp2: 64559ms
[03:04:15:22:25.273] sp2: 64560ms
[03:04:15:22:25.274] sp2: 64561ms
[03:04:15:22:25.275] sp2: 64562ms
[03:04:15:22:25.275] sp2: 64562ms
[03:04:15:22:25.276] sp2: 64563ms
[03:04:15:22:25.277] sp2: 64564ms
[03:04:15:22:25.278] sp2: 64565ms
[03:04:15:22:25.280] sp2: 64567ms
[03:04:15:22:25.282] sp2: 64569ms
[03:04:15:22:25.284] sp2: 64571ms
[03:04:15:22:25.286] sp2: 64573ms
[03:04:15:22:25.287] sp2: 64574ms
[03:04:15:22:25.288] sp2: 64575ms
[03:04:15:22:25.289] sp2: 64576ms
[03:04:15:22:25.290] sp2: 64577ms
[03:04:15:22:25.290] sp2: 64577ms
[03:04:15:22:25.291] sp2: 64578ms
[03:04:15:22:25.294] sp2: 64581ms
[03:04:15:22:25.296] sp2: 64583ms
[03:04:15:22:25.298] sp2: 64585ms
[03:04:15:22:25.300] sp2: 64587ms
[03:04:15:22:25.302] sp2: 64589ms
[03:04:15:22:25.304] sp2: 64591ms
[03:04:15:22:25.306] sp2: 64593ms
[03:04:15:22:25.308] sp2: 64595ms
[03:04:15:22:25.310] sp2: 64597ms
[03:04:15:22:25.312] sp2: 64599ms
[03:04:15:22:25.314] sp2: 64601ms
[03:04:15:22:25.315] sp2: 64602ms
[03:04:15:22:25.316] sp2: 64603ms
[03:04:15:22:25.317] sp2: 64604ms
[03:04:15:22:25.318] sp2: 64605ms
[03:04:15:22:25.319] sp2: 64606ms
[03:04:15:22:25.320] sp2: 64607ms
[03:04:15:22:25.321] sp2: 64608ms
[03:04:15:22:25.322] sp2: 64608ms
[03:04:15:22:25.322] sp2: 64609ms
[03:04:15:22:25.325] sp2: 64612ms
[03:04:15:22:25.326] sp2: 64613ms
[03:04:15:22:25.327] sp2: 64614ms
[03:04:15:22:25.328] sp2: 64615ms
[03:04:15:22:25.329] sp2: 64616ms
[03:04:15:22:25.330] sp2: 64617ms
[03:04:15:22:25.331] sp2: 64618ms
[03:04:15:22:25.332] sp2: 64619ms
[03:04:15:22:25.333] sp2: 64620ms
[03:04:15:22:25.334] sp2: 64621ms
[03:04:15:22:25.335] sp2: 64622ms
[03:04:15:22:25.336] sp2: 64623ms
[03:04:15:22:25.337] sp2: 64624ms
[03:04:15:22:25.338] sp2: 64625ms
[03:04:15:22:25.338] sp2: 64625ms
[03:04:15:22:25.341] sp2: 64628ms
[03:04:15:22:25.343] sp2: 64630ms
[03:04:15:22:25.345] sp2: 64632ms
[03:04:15:22:25.347] sp2: 64634ms
[03:04:15:22:25.348] sp2: 64635ms
[03:04:15:22:25.349] sp2: 64636ms
[03:04:15:22:25.350] sp2: 64637ms
[03:04:15:22:25.351] sp2: 64638ms
[03:04:15:22:25.352] sp2: 64639ms
[03:04:15:22:25.353] sp2: 64640ms
[03:04:15:22:25.353] sp2: 64640ms
[03:04:15:22:25.354] sp2: 64641ms
[03:04:15:22:25.355] sp2: 64642ms
[03:04:15:22:25.356] sp2: 64643ms
[03:04:15:22:25.357] sp2: 64644ms
[03:04:15:22:25.358] sp2: 64645ms
[03:04:15:22:25.359] sp2: 64646ms
[03:04:15:22:25.359] sp2: 64646ms
[03:04:15:22:25.360] sp2: 64647ms
[03:04:15:22:25.361] sp2: 64648ms
[03:04:15:22:25.362] sp2: 64649ms
[03:04:15:22:25.363] sp2: 64650ms
[03:04:15:22:25.365] sp2: 64652ms
[03:04:15:22:25.366] sp2: 64653ms
[03:04:15:22:25.369] sp2: 64656ms
[03:04:15:22:25.371] sp2: 64658ms
[03:04:15:22:25.372] sp2: 64659ms
[03:04:15:22:25.373] sp2: 64660ms
[03:04:15:22:25.374] sp2: 64661ms
[03:04:15:22:25.376] sp2: 64663ms
[03:04:15:22:25.377] sp2: 64664ms
[03:04:15:22:25.379] sp2: 64666ms
[03:04:15:22:25.381] sp2: 64668ms
[03:04:15:22:25.383] sp2: 64670ms
[03:04:15:22:25.384] sp2: 64671ms
[03:04:15:22:25.385] sp2: 64672ms
[03:04:15:22:25.386] sp2: 64673ms
[03:04:15:22:25.387] sp2: 64674ms
[03:04:15:22:25.390] sp2: 64677ms
[03:04:15:22:25.391] sp2: 64678ms
[03:04:15:22:25.392] sp2: 64679ms
[03:04:15:22:25.393] sp2: 64680ms
[03:04:15:22:25.394] sp2: 64681ms
[03:04:15:22:25.396] sp2: 64683ms
[03:04:15:22:25.398] sp2: 64685ms
[03:04:15:22:25.399] sp2: 64686ms
[03:04:15:22:25.400] sp2: 64687ms
[03:04:15:22:25.401] sp2: 64688ms
[03:04:15:22:25.402] sp2: 64689ms
[03:04:15:22:25.403] sp2: 64690ms
[03:04:15:22:25.403] sp2: 64690ms
[03:04:15:22:25.404] sp2: 64691ms
[03:04:15:22:25.405] sp2: 64692ms
[03:04:15:22:25.406] sp2: 64693ms
[03:04:15:22:25.407] sp2: 64694ms
[03:04:15:22:25.408] sp2: 64695ms
[03:04:15:22:25.409] sp2: 64696ms
[03:04:15:22:25.411] sp2: 64698ms
[03:04:15:22:25.413] sp2: 64700ms
[03:04:15:22:25.415] sp2: 64702ms
[03:04:15:22:25.416] sp2: 64703ms
[03:04:15:22:25.417] sp2: 64704ms
[03:04:15:22:25.418] sp2: 64705ms
[03:04:15:22:25.419] sp2: 64706ms
[03:04:15:22:25.421] sp2: 64708ms
[03:04:15:22:25.422] sp2: 64709ms
[03:04:15:22:25.423] sp2: 64710ms
[03:04:15:22:25.424] sp2: 64711ms
[03:04:15:22:25.424] sp2: 64711ms
[03:04:15:22:25.425] sp2: 64712ms
[03:04:15:22:25.426] sp2: 64713ms
[03:04:15:22:25.427] sp2: 64714ms
[03:04:15:22:25.428] sp2: 64715ms
[03:04:15:22:25.429] sp2: 64716ms
[03:04:15:22:25.431] sp2: 64718ms
[03:04:15:22:25.434] sp2: 64721ms
[03:04:15:22:25.436] sp2: 64723ms
[03:04:15:22:25.438] sp2: 64725ms
[03:04:15:22:25.439] sp2: 64726ms
[03:04:15:22:25.440] sp2: 64727ms
[03:04:15:22:25.441] sp2: 64728ms
[03:04:15:22:25.442] sp2: 64729ms
[03:04:15:22:25.443] sp2: 64730ms
[03:04:15:22:25.443] sp2: 64730ms
[03:04:15:22:25.444] sp2: 64731ms
[03:04:15:22:25.445] sp2: 64732ms
[03:04:15:22:25.446] sp2: 64733ms
[03:04:15:22:25.447] sp2: 64734ms
[03:04:15:22:25.448] sp2: 64735ms
[03:04:15:22:25.449] sp2: 64736ms
[03:04:15:22:25.449] sp2: 64736ms
[03:04:15:22:25.450] sp2: 64737ms
[03:04:15:22:25.451] sp2: 64738ms
[03:04:15:22:25.452] sp2: 64739ms
[03:04:15:22:25.453] sp2: 64740ms
[03:04:15:22:25.455] sp2: 64742ms
[03:04:15:22:25.457] sp2: 64744ms
[03:04:15:22:25.459] sp2: 64746ms
[03:04:15:22:25.461] sp2: 64748ms
[03:04:15:22:25.463] sp2: 64750ms
[03:04:15:22:25.465] sp2: 64752ms
[03:04:15:22:25.467] sp2: 64754ms
[03:04:15:22:25.478] commit tran: 11ms
[03:04:15:22:25.478] shkruajShitjeResult: 3
POST /shitje 200 67077ms - 254b

from node-mssql.

patriksimek avatar patriksimek commented on May 24, 2024

It doesn't look like a 20 rows as you said. Have you tried to execute requests without transaction?

from node-mssql.

RidiQirici avatar RidiQirici commented on May 24, 2024

Thank you Patrick, I found where the problem was. The function async.filter wasn't filtering anything, that was the reason why were so many rows to insert.

from node-mssql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.