int main(int argc, char **argv)
{
	int result;
	int upload_count;
	int rand_num;
	int file_index;
	char file_id[64];
	char storage_ip[IP_ADDRESS_SIZE];
	int count_sums[FILE_TYPE_COUNT];
	int i;
	struct timeval tv_start;
	struct timeval tv_end;
	int time_used;

	if (argc < 2)
	{
		printf("Usage: %s <process_index>\n", argv[0]);
		return EINVAL;
	}

	log_init();
	proccess_index = atoi(argv[1]);
	if (proccess_index < 0 || proccess_index >= PROCESS_COUNT)
	{
		printf("Invalid proccess index: %d\n", proccess_index);
		return EINVAL;
	}

	if ((result = load_file_contents()) != 0)
	{
		return result;
	}

	if ((result=test_init()) != 0)
	{
		return result;
	}

	if ((result=dfs_init(proccess_index)) != 0)
	{
		return result;
	}

	if (daemon(1, 1) != 0)
	{
		return errno != 0 ? errno : EFAULT;
	}

	memset(&storages, 0, sizeof(storages));
	upload_count = 0;
	for (i=0; i<FILE_TYPE_COUNT; i++)
	{
		upload_count += files[i].count;
		count_sums[i] = upload_count;
	}

	if (upload_count == 0)
	{
		return EINVAL;
	}

	memset(file_id, 0, sizeof(file_id));
	memset(storage_ip, 0, sizeof(storage_ip));

	start_time = time(NULL);
	srand(SRAND_SEED);
	result = 0;
	total_count = 0;
	success_count = 0;
	while (total_count < upload_count)
	{
		rand_num = (int)(upload_count * ((double)rand() / RAND_MAX));
		for (file_index=0; file_index<FILE_TYPE_COUNT; file_index++)
		{
			if (rand_num < count_sums[file_index])
			{
				break;
			}
		}

		if (files[file_index].upload_count >= files[file_index].count)
		{
			continue;
		}

		files[file_index].upload_count++;
		total_count++;

		gettimeofday(&tv_start, NULL);
		*storage_ip = '\0';

		result = upload_file(files[file_index].file_buff, files[file_index].bytes, file_id, storage_ip);
		gettimeofday(&tv_end, NULL);
		time_used = TIME_SUB_MS(tv_end, tv_start);
		files[file_index].time_used += time_used;

		add_to_storage_stat(storage_ip, result, time_used);
		if (result == 0) //success
		{
			success_count++;
			files[file_index].success_count++;

			fprintf(fpSuccess, "%d %d %s %s %d\n", 
				(int)tv_end.tv_sec, files[file_index].bytes, 
				file_id, storage_ip, time_used);
		}
		else //fail
		{
			fprintf(fpFail, "%d %d %d %d\n", (int)tv_end.tv_sec, 
				files[file_index].bytes, result, time_used);
			fflush(fpFail);
		}

		if (total_count % 100 == 0)
		{
			if ((result=save_stats_by_overall()) != 0)
			{
				break;
			}
			if ((result=save_stats_by_file_type()) != 0)
			{
				break;
			}

			if ((result=save_stats_by_storage_ip()) != 0)
			{
				break;
			}
		}

	}

	save_stats_by_overall();
	save_stats_by_file_type();
	save_stats_by_storage_ip();

	fclose(fpSuccess);
	fclose(fpFail);

	dfs_destroy();

	printf("proccess %d, time used: %ds\n", proccess_index, (int)(time(NULL) - start_time));
	return result;
}
Esempio n. 2
0
int TestUpload::Run(UINT32 (__stdcall * func_UploadFileByID)(const BYTE *pbyFileBuff, UINT32 nFileSize, const BYTE *pbyFileExtName, BYTE *pbyFileID),
					UINT32 (__stdcall * func_UploadSlaveFileByID)(const BYTE *pbyFileBuff, UINT32 nFileSize,
						const BYTE *pbyMasterGroupName, const BYTE *pbyMasterFileName,
						const BYTE *pbyPrefixName, const BYTE *pbyFileExtName,
						BYTE *pbyFileID))
{
	int result;
	int upload_count;
	int rand_num;
	int file_index;
	char file_id[256];
	int i;
	int time_used;
	SYSTEMTIME tStart;
	SYSTEMTIME tEnd;


	if ((result = load_file_contents()) != 0)
	{
		return result;
	}

	if ((result=test_init()) != 0)
	{
		return result;
	}

	upload_count = testFile.count;

	if (upload_count == 0)
	{
		return EINVAL;
	}

	memset(file_id, 0, sizeof(file_id));

	start_time = time(NULL);
	srand(0);
	result = 0;
	total_count = 0;
	success_count = 0;
	while (total_count < upload_count)
	{
		total_count++;
		GetLocalTime(&tStart);

		result = func_UploadFileByID((const BYTE*)testFile.file_buff, testFile.bytes, (const BYTE*)"jpg", (BYTE*)file_id);
	
		GetLocalTime(&tEnd);
		time_used = TIME_SUB_MS(tEnd, tStart);
		testFile.time_used += time_used;
		testFile.upload_count++;
		if (result == 0) //success
		{
			success_count++;
			testFile.success_count++;

			fprintf(fpSuccess, "%d %d %s %d\n", 
				(int)tEnd.wSecond, testFile.bytes, 
				file_id, time_used);
		}
		else //fail
		{
			fprintf(fpFail, "%d %d %d %d\n", (int)tEnd.wSecond, 
				testFile.bytes, result, time_used);
			fflush(fpFail);
		}


		if (total_count % 100 == 0)
		{
			if ((result=save_stats_by_overall()) != 0)
			{
				break;
			}
			if ((result=save_stats_by_file_type()) != 0)
			{
				break;
			}
		}

	}

	save_stats_by_overall();
	save_stats_by_file_type();

	fclose(fpSuccess);
	fclose(fpFail);

	return result;
}
Esempio n. 3
0
int TestDownload::Run(UINT32 (__stdcall * func_DownloadFileByID)(const BYTE *pbyFileID, BYTE *pbyFileBuff, UINT32 *nFileSize))
{
	int result;
	int i;
	int file_type;
	SYSTEMTIME tStart;
	SYSTEMTIME tEnd;
	int time_used;
	char storage_ip[IP_ADDRESS_SIZE];
	memset(storage_ip, 0, sizeof(storage_ip));

	if ((result = load_file_ids()) != 0)
	{
		return result;
	}

	if ((result=test_init()) != 0)
	{
		return result;
	}

	start_time = time(NULL);
	result = 0;
	total_count = 0;
	success_count = 0;
	UINT32 file_size;
	for (i=0; i<file_count; i++)
	{
		file_type = file_entries[i].file_type;
		files[file_type].download_count++;
		total_count++;

		GetLocalTime(&tStart);
		result = func_DownloadFileByID((const BYTE*)file_entries[i].file_id, buffer, (UINT32*)&file_size);
		GetLocalTime(&tEnd);
		time_used = TIME_SUB_MS(tEnd, tStart);
		files[file_type].time_used += time_used;

		if (result == 0) //success
		{
			success_count++;
			files[file_type].success_count++;
		}
		else //fail
		{
			fprintf(fpFail, "%d %d %s %s %d %d\n", (int)tEnd.wSecond, 
				files[file_type].bytes, file_entries[i].file_id, 
				storage_ip, result, time_used);
			fflush(fpFail);
		}

		if (total_count % 10000 == 0)
		{
			if ((result=save_stats_by_overall()) != 0)
			{
				break;
			}
			if ((result=save_stats_by_file_type()) != 0)
			{
				break;
			}
		}
	}

	save_stats_by_overall();
	save_stats_by_file_type();

	fclose(fpFail);

	for(int i = 0; i < file_count; i++)
	{
		free(file_entries[i].file_id);
	}
	free(file_entries);
	file_entries = NULL;

	char debugBuf[256];
	sprintf(debugBuf, "proccess %d, time used: %ds\n", proccess_index, (int)(time(NULL) - start_time));
	OutputDebugString(debugBuf);
	return result;
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	int result;
	int i;
	int file_type;
	char storage_ip[IP_ADDRESS_SIZE];
	struct timeval tv_start;
	struct timeval tv_end;
	int time_used;

	if (argc < 2)
	{
		printf("Usage: %s <process_index>\n", argv[0]);
		return EINVAL;
	}

	proccess_index = atoi(argv[1]);
	if (proccess_index < 0 || proccess_index >= PROCESS_COUNT)
	{
		printf("Invalid proccess index: %d\n", proccess_index);
		return EINVAL;
	}

	if ((result = load_file_ids()) != 0)
	{
		return result;
	}

	if ((result=test_init()) != 0)
	{
		return result;
	}

	if ((result=dfs_init(proccess_index)) != 0)
	{
		return result;
	}

	if (daemon(1, 1) != 0)
	{
		return errno != 0 ? errno : EFAULT;
	}

	/*
	printf("file_count = %d\n", file_count);
	printf("file_entries[0]=%s\n", file_entries[0].file_id);
	printf("file_entries[%d]=%s\n", file_count-1, file_entries[file_count-1].file_id);
	*/

	memset(&storages, 0, sizeof(storages));
	memset(storage_ip, 0, sizeof(storage_ip));

	start_time = time(NULL);
	result = 0;
	total_count = 0;
	success_count = 0;
	for (i=0; i<file_count; i++)
	{
		file_type = file_entries[i].file_type;
		files[file_type].delete_count++;
		total_count++;

		gettimeofday(&tv_start, NULL);
		*storage_ip = '\0';
		result = delete_file(file_entries[i].file_id, storage_ip);
		gettimeofday(&tv_end, NULL);
		time_used = TIME_SUB_MS(tv_end, tv_start);
		files[file_type].time_used += time_used;

		add_to_storage_stat(storage_ip, result, time_used);
		if (result == 0) //success
		{
			success_count++;
			files[file_type].success_count++;
		}
		else //fail
		{
			fprintf(fpFail, "%d %d %s %s %d %d\n", (int)tv_end.tv_sec, 
				files[file_type].bytes, file_entries[i].file_id, 
				storage_ip, result, time_used);
			fflush(fpFail);
		}

		if (total_count % 10000 == 0)
		{
			if ((result=save_stats_by_overall()) != 0)
			{
				break;
			}
			if ((result=save_stats_by_file_type()) != 0)
			{
				break;
			}

			if ((result=save_stats_by_storage_ip()) != 0)
			{
				break;
			}
		}
	}

	save_stats_by_overall();
	save_stats_by_file_type();
	save_stats_by_storage_ip();

	fclose(fpFail);

	dfs_destroy();

	printf("proccess %d, time used: %ds\n", proccess_index, (int)(time(NULL) - start_time));
	return result;
}
Esempio n. 5
0
int main(int argc, char **argv)
{
	int result;
	int file_index;
	int file_type;
	int file_size;
	char *conf_filename;
	char storage_ip[IP_ADDRESS_SIZE];
	struct timeval tv_start;
	struct timeval tv_end;
	int time_used;

	if (argc < 2)
	{
		printf("Usage: %s <process_index> [config_filename]\n", argv[0]);
		return EINVAL;
	}

	log_init();
	proccess_index = atoi(argv[1]);
	if (proccess_index < 0 || proccess_index >= PROCESS_COUNT)
	{
		printf("Invalid proccess index: %d\n", proccess_index);
		return EINVAL;
	}

	if (argc >= 3)
	{
		conf_filename = argv[2];
	}
	else
	{
		conf_filename = "/etc/fdfs/client.conf";
	}

	if ((result = load_file_ids()) != 0)
	{
		return result;
	}

	if ((result=test_init()) != 0)
	{
		return result;
	}

	if ((result=dfs_init(proccess_index, conf_filename)) != 0)
	{
		return result;
	}

#ifndef WIN32
	if (daemon(1, 1) != 0)
	{
		return errno != 0 ? errno : EFAULT;
	}
#endif

	/*
	printf("file_count = %d\n", file_count);
	printf("file_entries[0]=%s\n", file_entries[0].file_id);
	printf("file_entries[%d]=%s\n", file_count-1, file_entries[file_count-1].file_id);
	*/

	memset(&storages, 0, sizeof(storages));
	memset(storage_ip, 0, sizeof(storage_ip));

	start_time = time(NULL);
	srand(SRAND_SEED);
	result = 0;
	total_count = 0;
	success_count = 0;
	while (time(NULL) - start_time < TOTAL_SECONDS)
	{
		file_index = (int)(file_count * ((double)rand() / RAND_MAX));
		if (file_index >= file_count)
		{
			printf("file_index=%d!!!!\n", file_index);
			continue;
		}

		file_type = file_entries[file_index].file_type;
		files[file_type].download_count++;
		total_count++;

		gettimeofday(&tv_start, NULL);
		*storage_ip = '\0';
		result = download_file(file_entries[file_index].file_id, &file_size, storage_ip);
		gettimeofday(&tv_end, NULL);
		time_used = TIME_SUB_MS(tv_end, tv_start);
		files[file_type].time_used += time_used;

		add_to_storage_stat(storage_ip, result, time_used);
		if (result == 0) //success
		{
			if (file_size != files[file_type].bytes)
			{
				result = EINVAL;
			}
		}

		if (result == 0) //success
		{
			success_count++;
			files[file_type].success_count++;
		}
		else //fail
		{
			fprintf(fpFail, "%d %d %s %s %d %d\n", (int)tv_end.tv_sec, 
				files[file_type].bytes, file_entries[file_index].file_id, 
				storage_ip, result, time_used);
			fflush(fpFail);
		}

		if (total_count % 10000 == 0)
		{
			if ((result=save_stats_by_overall()) != 0)
			{
				break;
			}
			if ((result=save_stats_by_file_type()) != 0)
			{
				break;
			}

			if ((result=save_stats_by_storage_ip()) != 0)
			{
				break;
			}
		}
	}

	save_stats_by_overall();
	save_stats_by_file_type();
	save_stats_by_storage_ip();

	fclose(fpFail);

	dfs_destroy();

	printf("proccess %d, time used: %ds\n", proccess_index, (int)(time(NULL) - start_time));
	return result;
}