51Testing软件测试论坛

标题: 请帮忙看一下,为什么会Socket发送失败 [打印本页]

作者: 豆奶板蓝根    时间: 2008-8-11 09:24
标题: 请帮忙看一下,为什么会Socket发送失败
LR版本: LR8.1
Client OS:Windows Server 2003 Enterprise SP2(用VM虚拟出来的OS)
Server OS:IBM AS400

整套系统是属于CS架构,Server端程序在AS400上运行,Client端在Windows下运行,使用TCP方式通信。在性能测试过程中,使用LR来模拟Client端程序,对Server端进行性能测试。(最初录制时,用Windows Socket方式录制,后增强脚本)

但在性能测试过程中,出现了问题,请各位帮帮忙,看一下是什么问题。

在Virtual User Generator下,脚本运行一切正常。但是在Controller下,我把Run-Time Setting设置中的迭代次数Iteration Count从10~250这个值陆续放大的时候,会出现Socket数据包发送失败的情况,具体报错为“Action.c(102): Error: An error occurred while sending to the socket, Error Code: 9013”。当迭代次数设置为10的时候不会出现该错误,当迭代次数设置越来越大的时候,这种错误出现的概率也越来越高。

请教各位高人,帮我看一下这个是什么问题,有什么方法解决?

谢谢:)

[ 本帖最后由 豆奶板蓝根 于 2008-8-11 09:25 编辑 ]
作者: sqlserveroracle    时间: 2008-8-11 10:58
could you please post your source code about script,
but first, you must understand the iteration operation. iteration means when you finish the running script,the script must run again until the times of running script reach the value you set in run-time setting. so the scripts don't be executed at the time.
according to the problem you report, I just conclude that your server maybe not reponse the client request immediately.
作者: 豆奶板蓝根    时间: 2008-8-11 11:27
首先非常感谢二楼的。

在run-time setting中的Iteration间隔时间我使用的是“as soon as the previous iteration ends”,think time设置的是“Ignore think time”

下面我将贴出部分脚本,如下示。
作者: 豆奶板蓝根    时间: 2008-8-11 11:28
//vuser_init
vuser_init()
{
    lrs_startup(257);

        lr_load_dll("iso8583.dll");

    lrs_create_socket("socket0", "TCP", "LocalHost=<localport>", "Backlog=5",  LrsLastArg);

        lrs_create_socket("socket1", "TCP", "LocalHost=0", "Backlog=5",  LrsLastArg);

    lrs_create_socket("socket2", "TCP", "LocalHost=0", "Backlog=5",  LrsLastArg);

    lrs_create_socket("socket3", "TCP", "LocalHost=0", "Backlog=5",  LrsLastArg);

    lrs_accept_connection("socket0", "socket4");

    lrs_close_socket("socket0");

    lrs_create_socket("socket5", "TCP", "LocalHost=0", "RemoteHost=<remotehost>:<remoteport>",  LrsLastArg);

        lrs_set_send_timeout(60,0);

        lrs_set_recv_timeout(60,0);

        lrs_set_receive_option(EndMarker,EndMarker_None);

    return 0;
}
作者: 豆奶板蓝根    时间: 2008-8-11 11:29
//Action
#include "lrs.h"
#include "template.h"
typedef long time_t;
struct tm {
       int tm_sec; /* seconds after the minute - [0,59] */
       int tm_min; /* minutes after the hour - [0,59] */
       int tm_hour; /* hours since midnight - [0,23] */
       int tm_mday; /* day of the month - [1,31] */
       int tm_mon; /* months since January - [0,11] */
       int tm_year; /* years since 1900 */
       int tm_wday; /* days since Sunday - [0,6] */
       int tm_yday; /* days since January 1 - [0,365] */
       int tm_isdst; /* daylight savings time flag */
};
char oldField38[7];

char * psTsName = NULL;

Action()
{
        int i;
        char * templatebuf;
        int flag = 0;    //交易类型,0-独立交易,1-关联交易

        lr_continue_on_error(1);


        for (i=0; i<17; i++)
        {
        flag = msgtemplate.flag;
                templatebuf = msgtemplate.msg;
                psTsName = msgtemplate.casename;
                lr_output_message("Case NO. = [%s], Case Name =[%s]\n",msgtemplate.caseno,msgtemplate.casename);
                dotransaction(templatebuf,flag,psTsName);

        }

    lr_continue_on_error(0);
}

int dotransaction(char *templatebuf, int flag, char * psTsName)
{
        int rc,sendlen;
        char *inputbuf, buf8583[800], msghead[55], msglen[5], msgtype[5];

    memset(msglen,0,sizeof(msglen));
        memset(msgtype,0,sizeof(msgtype));
        strncpy(msglen, templatebuf, 4);
        memcpy(msgtype, templatebuf+50, 4);
        sendlen = atoi(msglen);

    memset(buf8583, 0, sizeof(buf8583));
        memcpy(buf8583, templatebuf+54, sendlen-50);
   
       
        memset(msghead,0,sizeof(msghead));
        memcpy(msghead,templatebuf,54);
   
           init_master_8583();       
        unpack_master_8583(buf8583);
        set_parm(msgtype,flag);
        sendlen = pack_master_8583(buf8583);
        sendlen += 50;


        memset(msglen, 0, sizeof(msglen));
        sprintf(msglen,"%04d",sendlen);
        memcpy(msghead, msglen, 4);
        memcpy(msghead+6, msglen, 4);

    inputbuf = (char*)malloc(sendlen+4);
        if (NULL == inputbuf)
        {
                lr_error_message("=====inputbuf内存分配失败!!!!=====");
                return -1;
        }
        memset(inputbuf,0,sendlen+4);
        memcpy(inputbuf,msghead,54);
        memcpy(inputbuf+54,buf8583,sendlen-50);


    lrs_set_send_buffer("socket5",inputbuf,sendlen+4);
    lr_start_transaction(psTsName);

        rc = lrs_send("socket5", "buf0", LrsLastArg);
    if (0!=rc)  {
             lr_error_message("An error occurred while sending to the socket, Error Code: %d", rc);
         lr_end_transaction(psTsName,LR_FAIL);
                 return -1;
        }
        lrs_free_buffer(inputbuf);
        lr_end_transaction(psTsName,LR_AUTO);

        return 0;
}

[ 本帖最后由 豆奶板蓝根 于 2008-8-11 11:32 编辑 ]
作者: 豆奶板蓝根    时间: 2008-8-11 11:41
标题: 回复 2# 的帖子
according to the problem you report, I just conclude that your server maybe not reponse the client request immediately
-----------------------------------
关于这一条,我在Server端查看过日志,Client端发送失败的消息,确实没有在Server端有记录
另外说明,Server端用的是小型机,处理能力是非常强的,我用PC端发送的消息,小数据量还不能对Server端造成压力。
作者: sqlserveroracle    时间: 2008-8-11 13:22
Thanks for your good source code for finding what cause the question.
according to Error Code: 9013, I look for its' meaning in some related document which say: Error in buffer translation. that means: maybe, the socket buffer have not been translated correctly.
now back to your souce code:
  for (i=0; i<17; i++)
        {
        flag = msgtemplate.flag;
                templatebuf = msgtemplate.msg;
                psTsName = msgtemplate.casename;
                lr_output_message("Case NO. = [%s], Case Name =[%s]\n",msgtemplate.caseno,msgtemplate.casename);
                dotransaction(templatebuf,flag,psTsName);

        }
// attention to following code
msgtemplate variable is in the circle for 17 times, I don't know where the msgtemplate derive from.
but I know, the msgtemplate is not initialized before you use.
for example:
when you first call dotransaction(....), it will modify templatebuf, then circle again
that's to say, at the second time,you then call dotransaction,it will modify templatebuf, that will happen
9013 error, just good luck, if any question, please contact me:qq:652466006,MSN:blzhang1@hotmail.com
作者: 豆奶板蓝根    时间: 2008-8-11 14:21
标题: 回复 7# 的帖子
// attention to following code
msgtemplate variable is in the circle for 17 times, I don't know where the msgtemplate derive from.
but I know, the msgtemplate is not initialized before you use.
for example:
when you first call dotransaction(....), it will modify templatebuf, then circle again
------------------------------------------------------------------------------------------------------------------
应该不是脚本的逻辑处理问题,因为我在Virtual User Generator中,设置Iteration Count为250运行时,是不存在Socket发送失败的这个问题的,但到了Controller中,发送量一旦变得比较大的时候,就出现问题了。

有没有可能是我发送的数据包大小的原因。我发送的buffer长度大概在5、6百个字节。
作者: sqlserveroracle    时间: 2008-8-11 15:18
I see, now I know maybe where the problem happened. according to what you said, the problem just happen when there are many virtual user ????not iteration(Is it all right)?? you can't explain very clearly, if this is multi-users' problem. I think it will happen in the dll library, you know, sometimes, dll library is very important for many things such as one copy in memory or providing many users to use it.
but for dll, you must consider synchronization and exclusion.
for your code:
unpack_master_8583(buf8583);
        set_parm(msgtype,flag);
        sendlen = pack_master_8583(buf8583);
        sendlen += 50;
maybe, the function unpack_master_8583 or pack_master_8583 will operate the buffer. I don't know what purpose the function have, even the function is sourced from dll library. the exclusion is very important for you consideration. you can also post the source code .
作者: 豆奶板蓝根    时间: 2008-8-11 15:46
在Controller中,我只用了一个虚拟用户在跑,所以应该不是你说的多用户调用dll产生的问题。
unpack_master_8583()函数的功能是ISO8583协议的解包程序,pack_master_8583()函数的功能是ISO8583的组包程序。

/*************************************************************/         
         unpack_master_8583(buf8583);
        set_parm(msgtype,flag);
        sendlen = pack_master_8583(buf8583);
        sendlen += 50;
/*************************************************************/         

上面一段代码的用途是,生成我需要的buffer,然后在Socket中把buffer发送出去到Server端。

[ 本帖最后由 豆奶板蓝根 于 2008-8-11 15:48 编辑 ]
作者: aks5201314    时间: 2008-8-11 17:14
楼主的服务器是AS/400,应该可以排除多用户访问时服务器没有及时响应客户端的原因.另外楼主能否将init()中的代码放action()中试试,因为你的init()中调用了DLL文件,还有创建SOCKET的函数.一般脚本中调用DLL文件都是为了处理一些动态数据或者完成一些复杂的算法功能.现在不知道你的DLL文件中的具体内容.还有这些函数
unpack_master_8583(buf8583);
  set_parm(msgtype,flag);
   sendlen = pack_master_8583(buf8583);
中的set_parm(msgtype,flag);是否是DLL文件的一个函数,这些函数之间是否有依赖关系.在VUGEN中你是单个用户问题不大,但在场景中多个用户多次迭代共享这些代码就不好说了.把init()中的代码放在action()中,多用户每次运行时都会初始化DLL文件和SOCKET连接,这样做也能更真实的模拟多用户访问操作服务器时的场景.楼主还可以保持你的脚本不修改的情况下,启用IP欺骗功能,虚拟几个IP地址+多用户访问服务器试试,看问题能否解决.(个人观点,仅供参考)
作者: cntester_com    时间: 2008-8-12 11:40
如果单用户增加跌代数增大,而出现的9013, LRS_TRANSALTION_ERR 9013 Error in buffer translation.
应该不关DLL的事情,
建议在错误点前加上思考时间后观察是不是还有问题。楼主的相关描述信息比较少,应该具体点。
Action.c(102):是哪行,搞不清楚,楼主也不说明白的?
你SEND相关的BUFFER前打印一下数据,看数值是否是正确的,然后接收BUFFER时候,也打印一下,看数据是不是有问题。

顺便楼主,是不是可以留个QQ什么的,大家有空可以多交流``我的43244619
作者: 豆奶板蓝根    时间: 2008-8-12 14:13
Action.c(102):   rc = lrs_send("socket5", "buf0", LrsLastArg);

当我把Iteration的时间间隔设置为0.05秒的时候,出现9013错误码的概率很小。
当我把Iteration的时间间隔设置为“as soon as the previous iteration ends”时,就会出现9013的错误。
作者: cntester_com    时间: 2008-8-12 14:23
rc = lrs_send("socket5", "buf0", LrsLastArg);
    if (0!=rc)  {
             lr_error_message("An error occurred while sending to the socket, Error Code: %d", rc);
         lr_end_transaction(psTsName,LR_FAIL);
                 return -1;
        }

=====================你改这样试试,有时候LRS函数很变态的,反正你也就是取返回值0判断```
====还有,你间隔时间怎么设置成0。05秒的???最好打印一下,看看SIZE和BUFFER的内存地址中,是不是已经正确的初始化为你所拼的数据
        char *Buffer;

        int Size;
.....

...
lrs_send("socket5", "buf0", LrsLastArg);
rc = lrs_get_buffer_by_name("buf0", &Buffer, &Size);
lr_output_message("_______Size1 = \"%d\"\n , Buffer1 = \"%s\"\n. ",Size,Buffer);
    if (0!=rc)  {
             lr_error_message("An error occurred while sending to the socket, Error Code: %d", rc);
         lr_end_transaction(psTsName,LR_FAIL);
                 return -1;
        }

[ 本帖最后由 cntester_com 于 2008-8-12 14:28 编辑 ]
作者: cgoods    时间: 2008-12-17 15:19
是不是Buffer太小了




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2