php malloc,PHP7 malloc task buff failed

在使用FastDFS 5.0.8版本,搭配PHP7和4GB内存的环境中进行文件上传压力测试时,发现存在内存泄露问题。错误日志显示在`storage_service.c`的第1828行,提示`malloc task buff failed`。PHP代码中尝试通过fastdfs库上传文件并获取信息,但返回了错误信息`Broken pipe`。通过`fdfs_monitor`监控,可以看到两个存储节点的详细状态,包括上传、下载次数和存储空间等信息。问题可能与文件上传过程中的资源管理有关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

benchmark环境:

fastdfs 5.0.8 + PHP7 +4G 内存+ 每次1M文件

用ab做压测的时候,多压测之后发现有内存泄露

ab -c100 -n1000 "http://192.168.10.244/ycf_fastdfs/test.php?fname=001"

日志输出:

···

tail -f /storage/logs/storaged.log

[2016-01-07 18:48:35] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:35] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:35] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:35] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:35] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:35] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:39] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:40] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:48:54] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

[2016-01-07 18:49:38] ERROR - file: storage_service.c, line: 1828, malloc task buff failed

···

代码

···

$info = $this->fdfs->storage_upload_by_filename($localfile, $ext_name,

array(), null, $this->tracker, $this->storage);

if (is_array($info)) {

$group_name = $info['group_name'];

$remote_filename = $info['filename'];

$source_info = $this->fdfs->get_file_info($group_name,

$remote_filename);

$source_ip = $source_info['source_ip_addr'];

$file_size = $source_info['file_size'];

$this->fdfs->tracker_close_all_connections();

return compact('group_name', 'remote_filename',

'source_ip', 'file_size');

}

···

PHP输出

array('retCode'=>$this->fdfs->get_last_error_no(),'errMsg'=>$this->fdfs->get_last_error_info());

···

array(2) { ["retCode"]=> int(32) ["errMsg"]=> string(11) "Broken pipe" }

···

monitor

···

/usr/bin/fdfs_monitor /etc/fdfs/client.conf

[2016-01-07 18:57:28] DEBUG - base_path=/storage, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

server_count=1, server_index=0

tracker server is 192.168.10.244:22122

group count: 1

Group 1:

group name = group1

disk total space = 465098 MB

disk free space = 291003 MB

trunk free space = 0 MB

storage server count = 2

active server count = 2

storage server port = 23000

storage HTTP port = 8888

store path count = 1

subdir count per path = 256

current write server index = 0

current trunk file id = 0

Storage 1:

id = 192.168.10.242

ip_addr = 192.168.10.242 ACTIVE

http domain =

version = 5.08

join time = 2015-12-29 21:24:45

up time = 2016-01-04 12:18:18

total storage = 934543 MB

free storage = 736624 MB

upload priority = 10

store_path_count = 1

subdir_count_per_path = 256

storage_port = 23000

storage_http_port = 8888

current_write_path = 0

source storage id = 192.168.10.243

if_trunk_server = 0

connection.alloc_count = 256

connection.current_count = 256

connection.max_count = 256

total_upload_count = 401413

success_upload_count = 401413

total_append_count = 0

success_append_count = 0

total_modify_count = 0

success_modify_count = 0

total_truncate_count = 0

success_truncate_count = 0

total_set_meta_count = 286222

success_set_meta_count = 286222

total_delete_count = 16

success_delete_count = 16

total_download_count = 49627

success_download_count = 49627

total_get_meta_count = 21

success_get_meta_count = 21

total_create_link_count = 0

success_create_link_count = 0

total_delete_link_count = 0

success_delete_link_count = 0

total_upload_bytes = 98746663528

success_upload_bytes = 98746663528

total_append_bytes = 0

success_append_bytes = 0

total_modify_bytes = 0

success_modify_bytes = 0

stotal_download_bytes = 2750713415

success_download_bytes = 2750713415

total_sync_in_bytes = 50608869108

success_sync_in_bytes = 50608869108

total_sync_out_bytes = 0

success_sync_out_bytes = 0

total_file_open_count = 1130799

success_file_open_count = 1130799

total_file_read_count = 49648

success_file_read_count = 49648

total_file_write_count = 1589464

success_file_write_count = 1589464

last_heart_beat_time = 2016-01-08 02:58:31

last_source_update = 2016-01-07 18:57:13

last_sync_update = 2016-01-07 18:57:13

last_synced_timestamp = 2016-01-07 18:55:26 (02m:01s delay)

Storage 2:

id = 192.168.10.243

ip_addr = 192.168.10.243 ACTIVE

http domain =

version = 5.08

join time = 2015-12-29 21:09:51

up time = 2016-01-04 20:21:36

total storage = 465098 MB

free storage = 291003 MB

upload priority = 10

store_path_count = 1

subdir_count_per_path = 256

storage_port = 23000

storage_http_port = 8888

current_write_path = 0

source storage id =

if_trunk_server = 0

connection.alloc_count = 256

connection.current_count = 256

connection.max_count = 256

total_upload_count = 403204

success_upload_count = 403204

total_append_count = 0

success_append_count = 0

total_modify_count = 0

success_modify_count = 0

total_truncate_count = 0

success_truncate_count = 0

total_set_meta_count = 282311

success_set_meta_count = 282311

total_delete_count = 0

success_delete_count = 0

total_download_count = 45234

success_download_count = 45234

total_get_meta_count = 0

success_get_meta_count = 0

total_create_link_count = 0

success_create_link_count = 0

total_delete_link_count = 0

success_delete_link_count = 0

total_upload_bytes = 50603269563

success_upload_bytes = 50603269563

total_append_bytes = 0

success_append_bytes = 0

total_modify_bytes = 0

success_modify_bytes = 0

stotal_download_bytes = 2508863994

success_download_bytes = 2508863994

total_sync_in_bytes = 98749240732

success_sync_in_bytes = 98749240732

total_sync_out_bytes = 0

success_sync_out_bytes = 0

total_file_open_count = 1130942

success_file_open_count = 1130942

total_file_read_count = 45234

success_file_read_count = 45234

total_file_write_count = 1593312

success_file_write_count = 1593312

last_heart_beat_time = 2016-01-08 02:58:39

last_source_update = 2016-01-07 18:57:27

last_sync_update = 2016-01-07 18:57:27

last_synced_timestamp = 2016-01-07 18:55:22 (01m:51s delay)

···

#include <stdio.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <memory.h> #include <pthread.h> #include <mqueue.h> #define MSGLENGTH 5 #define MSG "hello" static void* send_task(void* argc) { printf("in send_task\n"); mqd_t mqd0, mqd1; struct mq_attr attr; size_t msg_len = 0; int msg_prio = 1; void *recv_buff = NULL; /* 打开消息队列,并获取其属性,分配读缓冲区 */ mqd0 = mq_open("/mqueue_demo0", O_CREAT|O_WRONLY, 0, NULL); mqd1 = mq_open("/mqueue_demo1", O_CREAT|O_RDONLY, 0, NULL); mq_getattr(mqd1, &attr); recv_buff = malloc(attr.mq_msgsize); /* 发送消息 */ mq_send(mqd0, MSG, MSGLENGTH, msg_prio); /* 接收消息 并打印 */ msg_len = mq_receive(mqd1, recv_buff, attr.mq_msgsize, &msg_prio); printf("send_task: msg[%s] msg_length[%d] msg_prio[%d]\n", (char*)recv_buff, msg_len, msg_prio); return NULL; } static void* receive_task(void* argc) { printf("in receive_task\n"); mqd_t mqd0, mqd1; struct mq_attr attr; void *buff = NULL; char msg[10] = {0}; ssize_t msg_len = 0; int msg_prio = 0; /* 打开消息队列,并获取其属性,分配读缓冲区 */ mqd0 = mq_open("/mqueue_demo0", O_RDONLY); mq_getattr(mqd0, &attr); buff = malloc(attr.mq_msgsize); mqd1 = mq_open("/mqueue_demo1", O_WRONLY); /* 接收消息 */ msg_len = mq_receive(mqd0, buff, attr.mq_msgsize, &msg_prio); printf("receive_task: msg[%s] msg_length[%d] msg_prio[%d]\n", (char*)buff, msg_len, msg_prio); /* 验证消息 */ if(strcmp(buff, MSG)==0) { strcpy(msg, "OK"); } else { strcpy(msg, "ERROR"); } /* 发送响应消息 */ mq_send(mqd1, msg, 10, 2); return NULL; } int mqueue_demo(void) { pthread_t tid_send, tid_receive; /* 创建消费者任务 */ pthread_create(&tid_send, NULL, send_task, NULL); pthread_create(&tid_receive, NULL, receive_task, NULL); pthread_join(tid_send, NULL); pthread_join(tid_receive, NULL); return 0; }
最新发布
03-22
``` static int s_iServerSocket = 0; static stNetAddr stClient = {0}; //static pthread_t s_stServerThread; int TCPSvr_Run(void) { int iRet = -1; int iClientSocket; int iTaskID = 0; int iCLientNumber = 0; struct sockaddr_in stClientaddr; socklen_t addrlen = sizeof(stClientaddr); if (s_iServerSocket <= 0) { cmn_PrtError("server socket not available"); } if(listen(s_iServerSocket,cmnDfn_MAX_CLIENT) < 0) { cmn_PrtError("listen error"); } while (g_iExit == 0) { if(((iClientSocket = accept(s_iServerSocket, (struct sockaddr *)&stClientaddr,&addrlen))) < 0) { cmn_PrtError("accept failed"); } stClient.iServerSocket = iClientSocket; stClient.iClientNumber = iCLientNumber++; if(ThreadPoolSubmit(TCPRcvTrd, &stClient,&iTaskID) < 0) { cmn_PrtError("Error in submitting task to thread pool"); } if(ThreadPoolSubmit(TCPSndTrd, &stClient,&iTaskID) < 0) { cmn_PrtError("Error in submitting task to thread pool"); } } iRet = 0; _Exit: return iRet; } static int s_iClientSocket; static struct sockaddr_in stServerAddr; static stNetAddr stServer = {0}; //static pthread_t s_iClientPhread; int TCPClnt_Run(void) { int iRet = -1; int iTaskID = 0; //struct sockaddr_in stServerAddr; if(s_iClientSocket == -1) { cmn_PrtError("Client socket not available"); } if(connect(s_iClientSocket, (struct sockaddr *)&stServerAddr, sizeof(stServerAddr)) < 0) { cmn_PrtError("Error in connecting to server"); } stServer.iServerSocket = s_iClientSocket; if(ThreadPoolSubmit(TCPSndTrd,&stServer,&iTaskID) < 0) { cmn_PrtError("Error in submitting task to thread pool"); } if (ThreadPoolSubmit(TCPRcvTrd,&stServer,&iTaskID) < 0) { cmn_PrtError("Error in submitting task to thread pool"); } while (g_iExit == 0) { } iRet = 0; _Exit: return iRet; } void* TCPRcvTrd(void *arg) { //int iSockfd = *(int*)arg; //int iSockfd = (int)(intptr_t)arg; //int iLoopNum = 0; stNetAddr * ServerAddr = (stNetAddr *)arg; int iSockfd = ServerAddr->iServerSocket; int iClientNum = ServerAddr->iClientNumber; char crcvBuffer[cmnDfn_BUFF_LEN]; int iBytesReceived; unsigned long long ulTotalBytes = 0; struct timeval stStartTime; struct timeval stEndTime; //struct timeval stDisplayedTime = {0}; float fElapsedTime; float fNetSpeed; gettimeofday(&stStartTime, NULL); while (g_iExit == 0) { if((iBytesReceived = recv(iSockfd, crcvBuffer, sizeof(crcvBuffer), 0)) < 0) { cmn_PrtError("Error in receiving data"); } else if(iBytesReceived == 0) { printf("Client disconnected\n"); break; } ulTotalBytes += iBytesReceived; gettimeofday(&stEndTime,NULL); fElapsedTime = (stEndTime.tv_sec - stStartTime.tv_sec) + (stEndTime.tv_usec - stStartTime.tv_usec) / 1000000.0; fNetSpeed = ((float)ulTotalBytes * 8) / (fElapsedTime * 1000 * 1000); if (fElapsedTime >= DISPLAY_INTERVAL) { //printf("Received: %d bytes\n", ulTotalBytes); if(ServerAddr->iByteNumber != 0) { printf("Client %d Net Speed: %.2f Mbps\r", iClientNum,fNetSpeed); fflush(stdout); } else if(ServerAddr->iByteNumber == 0) { printf("Net Speed: %.2f Mbps\n", fNetSpeed); fflush(stdout); } stStartTime = stEndTime; ulTotalBytes = 0; } } _Exit: //close(iSockfd); pthread_exit(NULL); }```检查代码是否有bug并给出解决方案
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值