gpt4 book ai didi

c - 为什么这段代码在服务器上执行需要很长时间

转载 作者:行者123 更新时间:2023-11-30 16:49:19 26 4
gpt4 key购买 nike

我们使用 LoadRunner 来运行应用程序的性能测试。测试通常用 Ansi-C 编写。

我们有一个简单的base64编码函数:

void base64encode(char *src, char *dest, int srcLen, int destLen)
{
int i=0;
int slen= srcLen;
for(i=0;i<slen && i<destLen;i+=3,src+=3)
{
*(dest++)=base64encode_lut[(*src&0xFC)>>0x2];
*(dest++)=base64encode_lut[(*src&0x3)<<0x4|(*(src+1)&0xF0)>>0x4];
*(dest++)=((i+1)<slen)?base64encode_lut[(*(src+1)&0xF)<<0x2|(*(src+2)&0xC0)>>0x6]:'=';
*(dest++)=((i+2)<slen)?base64encode_lut[*(src+2)&0x3F]:'=';
}
*dest='\0';
}

此代码在开发人员计算机(64 位 Windows 10 计算机)上运行时,代码在一秒内运行一个简单图像(srcLen 大约 7k)。当在生产服务器(32 位 Windows 2012、VM)上运行时,同一镜像的执行时间为 10 到 20 分钟。

谁能解释一下为什么以及如何避免这个问题?我不确定是 LoadRunner 的问题还是代码的问题。

编辑:添加调用编码函数的代码:

long infile; // file pointer
char *buffer; // buffer to read file contents into
char *filename = "DFC_COLOR.jpg"; // file to read
int fileLen; // file size
int bytesRead; // bytes read from file
char *encoded;
int dest_size;

web_set_max_html_param_len("999999999");
infile = fopen(filename, "rb");
if (!infile) {
lr_error_message("Unable to open file %s", filename);
return;
}

// get the file length
fseek(infile, 0, SEEK_END);
fileLen = ftell(infile);
fseek(infile, 0, SEEK_SET);
lr_log_message("File length is: %9d bytes.", fileLen);


// Allocate memory for buffer to read file
buffer = (char *)malloc(fileLen + 1);
if (!buffer) {
lr_error_message("Could not malloc %10d bytes", fileLen + 1);
fclose(infile);
return;
}

// Read file contents into buffer
bytesRead = fread(buffer, 1, fileLen, infile);
if (bytesRead != fileLen)
{
lr_error_message("File length is %10d bytes but only read %10d bytes", fileLen, bytesRead);
}
else
{
lr_log_message("Successfully read %9d bytes from file: ", bytesRead);
}
fclose(infile);


// Save the buffer to a loadrunner parameter
lr_save_var(buffer, bytesRead, 0, "fileDataParameter");

// calculate the destination size
dest_size = 1 + ((bytesRead + 2) / 3 * 4);
encoded = (char *)malloc(dest_size);
memset(encoded, 0, dest_size);

// encode the buffer
base64encode(buffer, encoded, bytesRead, dest_size);

最佳答案

在非共享/代理资源物理机上运行单个虚拟用户,看看是否具有相同的性能。您不想确定虚拟机环境中的优先级和资源池。您可能正在高度过载的 VM 主机上运行,​​并且您只需等待虚拟机管理程序决定谁在何时获得给定的资源集。将单个虚拟用户移动到单个硬件主机可以提供通用的苹果与梨(橙子与金橘)的比较基础。

LoadRunner 还包括符合 RFC 的 Base64 编码和解码算法作为其核心集的一部分,因此您无需重新编码。通常,这用作 SMTP 或 DNS 虚拟用户的一部分,但您可以加载 DLL、对功能进行原型(prototype)设计并继续前进。您可以在\include\mic_socket.h 头文件中找到现有的函数原型(prototype)。这是一篇关于如何实现这一点的精彩文章。我知道编辑们会尖叫并将其降级为外部链接,因此您可能希望快速捕获链接

https://northwaysolutions.com/blog/loadrunner-vugen-encoding-and-decoding-base64/#.WL1vZxLytlc

处理此问题的另一种方法是作为数据格式扩展。解码已作为基本扩展涵盖,因此您只需在需要时处理编码即可。使用 Google 提取对 Loadrunner、DFE 和 base64 的引用以获取适当的项目。您还可以在本地文档集中找到 DFE 开发人员指南,该指南随 LoadRunner 副本一起安装。

关于c - 为什么这段代码在服务器上执行需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42618075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com