int SP_NKEndPointTableConfig :: init( const char * configFile ) { int ret = -1; SP_NKIniFile iniFile; if( 0 == iniFile.open( configFile ) ) ret = init( &iniFile ); return ret; }
SP_NKEndPointTable * SP_NKEndPointTableConfig :: readTable( const char * configFile ) { SP_NKEndPointTable * table = NULL; SP_NKIniFile iniFile; if( 0 == iniFile.open( configFile ) ) table = readTable( &iniFile ); return table; }
int SP_HiveDBClientConfig :: init( const char * configFile ) { int ret = -1; mImpl->mSocketPoolConfig = new SP_NKSocketPoolConfig(); mImpl->mEndPointTableConfig = new SP_NKEndPointTableConfig(); SP_NKIniFile iniFile; if( 0 == iniFile.open( configFile ) ) { ret = mImpl->mSocketPoolConfig->init( &iniFile, "SocketPool" ); ret |= mImpl->mEndPointTableConfig->init( &iniFile ); } return ret; }
int main( int argc, char * argv[] ) { signal( SIGPIPE, SIG_IGN ); extern char *optarg ; int c ; const char * type = NULL; while( ( c = getopt ( argc, argv, "f:t:c:r:w:ov" ) ) != EOF ) { switch ( c ) { case 'f': gConfigFile = optarg; break; case 't': type = optarg; break; case 'c': gClients = atoi( optarg ); break; case 'r': gReadTimes = atoi( optarg ); break; case 'w': gWriteTimes = atoi( optarg ); break; case 'o': SP_NKLog::setLogLevel( LOG_DEBUG ); SP_NKLog::init4test( "teststress" ); //SP_NKSocket::setLogSocketDefault( 1 ); break; case '?' : case 'v' : showUsage( argv[0] ); } } int rpcType = SP_HiveDBClientConfig::eJsonRpc; if( NULL != type && 0 == strcasecmp( type, "protobuf" ) ) { rpcType = SP_HiveDBClientConfig::eProtoBufRpc; } SP_HiveDBClient client; assert( 0 == client.init( gConfigFile, rpcType ) ); SP_NKIniFile iniFile; iniFile.open( gConfigFile ); gTableKeyMax = iniFile.getValueAsInt( "EndPointTable", "TableKeyMax" ); printf( "TableKeyMax %d\n", gTableKeyMax ); pthread_t * thrlist = (pthread_t*)calloc( sizeof( pthread_t ), gClients ); pthread_mutex_lock( &gBeginMutex ); printf( "begin to create thread ...\n" ); for( int i = 0; i < gClients; i++ ) { if( 0 != pthread_create( &(thrlist[i]), NULL, threadFunc, &client ) ) { printf( "pthread_create fail, index %d, errno %d, %s\n", i, errno, strerror( errno ) ); exit( -1 ); } } printf( "begin to execute ...\n" ); pthread_mutex_unlock( &gBeginMutex ); SP_NKClock clock; for( int i = 0; i < gClients; i++ ) { pthread_join( thrlist[i], NULL ); } free( thrlist ); printf( "\n" ); int usedTime = clock.getAge(); float writePerSeconds = ( gTotalWriteTimes * 1000.0 ) / usedTime; float readPerSeconds = ( gTotalReadTimes * 1000.0 ) / usedTime; printf( "Total Used Time: %d (ms), Write %d (%.2f), Read %d (%.2f), Fail %d\n", usedTime, gTotalWriteTimes, writePerSeconds, gTotalReadTimes, readPerSeconds, gTotalFailTimes ); return 0; }