//压力测试工具,分多进程和多线程两种场景
#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[