fastdfs多线程长连接

这是一个使用C语言实现的FastDFS多线程压力测试工具,用于模拟上传文件操作。程序通过命令行参数配置线程数、每个线程的请求次数,并支持连接池管理,以提高上传效率。

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

//压力测试工具,分多进程和多线程两种场景
#include <errno.h>
#include <pthread.h>
#include <signal.h>

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "fdfs_client.h"
#include "fdfs_global.h"
#include "fdfs_base64.h"
#include "logger.h"

void
TestUsage ( int iIsThread,char *argv[] )
{
    if(iIsThread)
    {
        printf ( "Usage: %s -t ThreadCount -c SendCountPerThread /n", argv[0] );
        printf("<conf operation>/n" /
                "/toperation: upload, download, getmeta, setmeta, " /
                "delete and query_servers/n", argv[0]);
        printf ( "e.g.:  %s -t 30 -c 100 ../conf/client.conf upload file/n", argv[0] );
    }
    else
    {
        printf ( "Usage: %s -t ProcessCount -c SendCountPerProcess/n", argv[0] );
        printf("<conf operation>/n" /
                "/toperation: upload, download, getmeta, setmeta, " /
                "delete and query_servers/n", argv[0]);
        printf ( "e.g.:  %s -t 30 -c 100 ../conf/client.conf upload file/n", argv[0] );
    }
}

static int nSum = 0,nTradeOK=0,nTradeFailed=0;
static int OverThread = 0;
int nThreadCount=1,nReqCount=1,nTimeAllUsed=0;
static pthread_mutex_t theSumMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t theConnMutex = PTHREAD_MUTEX_INITIALIZER;
char server[16]={0};
int port;

char operation[64]={0};
char conf_filename[64]={0};
char local_filename[64]={0};

//typedef void * (*ThreadFunction)(void *pParam);
int CreateThread(void *(* pFunction)(void *), void *pParam)
{
    int nReturn = 0;
    pthread_t tid;

    if(pthread_create(&tid, NULL, pFunction, pParam) != 0)
    {
        return(0);
    }

    pthread_detach(tid);

    nReturn = (int)tid;

    if( nReturn <-1 )
    {
        return 1024;
    }
    else
    {
        return(nReturn);
    }
}

// befor you definition you would be user ,mast have state.
void StartApp (  );

int main ( int argc, char **argv )
{
    int n;

    if (argc <= 6)
    {
        TestUsage(1,argv);
        exit(1);
    } 
    if (strchr(argv[1], '-') == NULL)
    {
        TestUsage(1,argv);
        exit(1);
    }

    for ( n = 1; n < argc; ++n )
    {
        // read garam from command,for create number of  thread
        if ( strcmp ( argv[n], "-t" ) == 0 )
        {
            n++;
            nThreadCount=atoi ( argv[n] );
        }
        // read garam from command, for total every thread has how mutch request
        else if ( strcmp ( argv[

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值