通过Tedious调用简单的存储过程是否花费这么长时间是有原因的吗?

时间:2019-04-30 18:45:27

标签: node.js performance tedious

我注意到,当调用一个简单的对表执行INSERT的简单存储过程CreateStatusReport时,通常我会花很长的时间来执行我(不管是好是坏)一些TDS开销,或者也许是我调用它的方式。

这是在Node.js REST API中调用的TDS代码:

function createReport(req, res) {
    let isReleased = false;

    let connection = new Connection(config);  

    connection.on('connect', function(err) {  
        let sql = "CreateStatusReport";

        if (err) console.log("**CN-ERROR", err);

        let request = new Request(sql, (err)=>{
            if (err) {
                console.log("**RQ-ERROR**", err);
            }
        });

        // Check to see if user clicked the "Release" button...
        if (typeof req.body.release != 'undefined')
            isReleased = true;

        request.addParameter('empid', TYPES.NVarChar, req.body.empid);
        request.addParameter('userid', TYPES.NChar, req.body.userid);
        request.addParameter('firstname', TYPES.NVarChar, req.body.fname);
        request.addParameter('lastname', TYPES.NVarChar, req.body.lname);
        request.addParameter('title', TYPES.NVarChar, req.body.title);
        request.addParameter('cabinet', TYPES.NVarChar, req.body.cabinet);
        request.addParameter('office', TYPES.NVarChar, req.body.office);
        request.addParameter('division', TYPES.NVarChar, req.body.division);
        request.addParameter('branch', TYPES.NVarChar, req.body.branch);
        request.addParameter('perstart', TYPES.VarChar, req.body.periodStart);
        request.addParameter('perend', TYPES.VarChar, req.body.periodEnd);
        request.addParameter('status', TYPES.NVarChar, req.body.status);
        request.addParameter('needs', TYPES.NVarChar, req.body.needs);
        request.addParameter('goals', TYPES.NVarChar, req.body.goals);
        request.addParameter('concerns', TYPES.NVarChar, req.body.concerns);
        request.addParameter('released', TYPES.Bit, isReleased);

        connection.callProcedure(request);

        request.on("requestCompleted", ()=> {
            res.redirect("/kudos")    
        });
    });  
}

存储过程非常简单,因此我将“胆量”放在这里:

INSERT INTO [status-report] (empid, [userid], firstname, lastname, title,[cabinet], [office], [division], [branch], [period-start], [period-end], [date-posted], [status], needs, goals, concerns, released) 
VALUES (@empid, @userid, @firstname, @lastname, @title, @cabinet, @office, @division, @branch, @perstart, @perend, GETDATE(), @status, @needs, @goals, @concerns, @released)

将记录实际创建到系统中可能要花费几秒钟的时间,我不知道为什么,因为该系统位于高性能生产系统上。

我在这里有些事要注意吗?关于如何找到根本原因的任何建议?

谢谢!

更新

USE [kudos]
GO

/****** Object:  StoredProcedure [dbo].[GetList]    Script Date: 5/1/2019 4:39:50 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[GetList]
AS
BEGIN
    SET NOCOUNT ON

    SELECT 
        [id],
        [empid],
        [lastname] + ', ' + [firstname] AS [name],
        LTRIM(RTRIM([userid])) AS [userid],
        [title],
        [cabinet],
        [office],
        [division],
        [branch],
        CONVERT(nvarchar(10), [period-start], 110) AS [periodstart],
        CONVERT(nvarchar(10), [period-end], 110) AS [periodend], 
        CONVERT(nvarchar(10), [date-posted], 110) AS [dateposted],
        IIF(released = 1, 'Released', 'In Progress') AS [released]
    FROM 
        [status-report] 
    WHERE 
        [date-posted] BETWEEN GETDATE() - 21 AND GETDATE() 
    ORDER BY 
        [date-posted] DESC
END
GO

1 个答案:

答案 0 :(得分:0)

这是一个ID10T错误(我的)。生产中有负载均衡器。有时会打电话,有时不是因为两个系统上的代码都不同步。