summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
author彭宣正 <[email protected]>2021-06-02 15:49:24 +0800
committer彭宣正 <[email protected]>2021-06-02 15:51:06 +0800
commitda3bc1db06ef3ecd2aa76ffe58e5b14e5828f3c7 (patch)
tree070e78d0fdd69538271996e0a4c70741b86c6270 /example
parent20e6f942cd8a45bd8846e90e6d2934f26b3a5303 (diff)
修复add_hos_info导致的segment faultv1.0.25
Diffstat (limited to 'example')
-rw-r--r--example/demo/hos_upload_complete.cpp2
-rw-r--r--example/demo/hos_write_complete.cpp16
-rw-r--r--example/performance/HosClientPerformance.cpp35
-rwxr-xr-xexample/performance/test.sh8
4 files changed, 31 insertions, 30 deletions
diff --git a/example/demo/hos_upload_complete.cpp b/example/demo/hos_upload_complete.cpp
index efe8c47c..68740fb4 100644
--- a/example/demo/hos_upload_complete.cpp
+++ b/example/demo/hos_upload_complete.cpp
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
file_to_buffer(object, buf, &buf_size);
debuginfo("hos_client_init start ...\n");
- hos_client_handle handle = hos_client_create("192.168.44.10", 9098, "default", "default", 3000);
+ hos_client_handle handle = hos_client_create("192.168.44.12", 9098, "default", "default", 3000);
if (handle == NULL)
{
debuginfo("error:hos_client_handle\n");
diff --git a/example/demo/hos_write_complete.cpp b/example/demo/hos_write_complete.cpp
index 490cbdd2..96f64b9b 100644
--- a/example/demo/hos_write_complete.cpp
+++ b/example/demo/hos_write_complete.cpp
@@ -15,7 +15,7 @@ extern "C"
//#define test_times 10000
-#define debuginfo (void)
+#define debuginfo printf
typedef struct userdata_s
{
@@ -59,7 +59,7 @@ void callback(bool result, const char *error, const char *bucket, const char *ob
int main(int argc, char *argv[])
{
- if (argc != 4)
+ if (argc != 3)
{
debuginfo("usege: singThread [bucket name] [object name]\n");
return -1;
@@ -69,7 +69,6 @@ int main(int argc, char *argv[])
int i = 0;
char *bucket = argv[1];
char *object = argv[2];
- int test_times = atoi(argv[3]);
char *buf = (char *)malloc(1024 * 1024 * 40);
size_t buf_size;
int mode = FILE_MODE;
@@ -79,7 +78,7 @@ int main(int argc, char *argv[])
file_to_buffer(object, buf, &buf_size);
debuginfo("hos_client_init start ...\n");
- hos_client_handle handle = hos_client_create("192.168.40.223", 9098, "default", "default", 400);
+ hos_client_handle handle = hos_client_create("192.168.44.12", 9098, "default", "default", 100);
//hos_client_handle handle = hos_client_create("http://192.168.32.10:9098/hos/", "default", "default", 4);
if (handle == NULL)
{
@@ -108,14 +107,10 @@ int main(int argc, char *argv[])
mode = FILE_MODE;
debuginfo("hos_upload_file start ...\n");
clock_gettime(CLOCK_MONOTONIC, &start);
- for (i = 0; i < test_times; i++)
- {
- fd[i] = hos_open_fd(handle, bucket, object, callback, (void *)&data, 0, mode);
- hos_write(fd[i], object, 0, 0);
- }
+ fd[0] = hos_open_fd(handle, bucket, object, callback, (void *)&data, 0, mode);
+ hos_write(fd[0], object, 0, 0);
clock_gettime(CLOCK_MONOTONIC, &end);
time = calc_time(start, end);
- time /= test_times;
printf("hos_upload_file spent %llu ns\n", time);
debuginfo("hos_upload_file end ...\n");
#else
@@ -151,7 +146,6 @@ int main(int argc, char *argv[])
//printf("start:%lu\n", start.tv_sec * 1000 * 1000 * 1000 + start.tv_nsec);
//printf("finished:%lu\n", finished.tv_sec * 1000 * 1000 * 1000 + finished.tv_nsec);
time = calc_time(start, finished);
- time /= test_times;
printf("hos upload finished spent %llu ns\n", time);
}
diff --git a/example/performance/HosClientPerformance.cpp b/example/performance/HosClientPerformance.cpp
index 8c115cd0..ac2a6175 100644
--- a/example/performance/HosClientPerformance.cpp
+++ b/example/performance/HosClientPerformance.cpp
@@ -69,8 +69,7 @@ typedef struct userdata_s
static size_t calc_time(struct timespec start, struct timespec end)
{
- return (end.tv_sec * 1000 * 1000 * 1000 + end.tv_nsec -
- (start.tv_sec * 1000 * 1000 * 1000 + start.tv_nsec));
+ return (end.tv_sec - start.tv_sec) * 1000 * 1000 * 1000 + end.tv_nsec - start.tv_nsec;
}
int read_file_list(const char *path, char file_name[][256])
@@ -216,7 +215,7 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
{
int i = 0;
int j = 0;
- size_t fd = 0;
+ size_t fd[1000] = {0};
size_t tmp = 0;
size_t rest = 0;
struct timespec tstart, ttmp;
@@ -230,11 +229,11 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
int drop = 0;
double variance = 0.00;
double average = 0.00;
- long record[1000] = {0};
+ long record[30000] = {0};
if (conf->slice)
{
- fd = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
+ fd[0] = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
for (i = 0; i < test_times; i++)
{
j = 0;
@@ -245,10 +244,10 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
rest = buff_len - tmp;
if (rest < conf->slice)
{
- hos_write(fd, &buff[tmp], rest, thread_info->thread_num);
+ hos_write(fd[0], &buff[tmp], rest, thread_info->thread_num);
break;
}
- hos_write(fd, &buff[tmp], conf->slice, thread_info->thread_num);
+ hos_write(fd[0], &buff[tmp], conf->slice, thread_info->thread_num);
j++;
}
clock_gettime(CLOCK_MONOTONIC, &ttmp);
@@ -272,7 +271,7 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
if (conf->mode & APPEND_MODE)
{
- fd = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
+ fd[0] = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
#if 1
for (i = 0; i < test_times; i++)
{
@@ -285,10 +284,10 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
rest = buff_len - tmp;
if (rest < conf->append_size)
{
- hos_write(fd, &buff[tmp], rest, thread_info->thread_num);
+ hos_write(fd[0], &buff[tmp], rest, thread_info->thread_num);
break;
}
- hos_write(fd, &buff[tmp], conf->append_size, thread_info->thread_num);
+ hos_write(fd[0], &buff[tmp], conf->append_size, thread_info->thread_num);
j++;
}
#if 1
@@ -315,14 +314,14 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
for (i = 0; i < test_times; i++)
{
clock_gettime(CLOCK_MONOTONIC, &tstart);
- fd = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
- ret = hos_write(fd, buff, buff_len, thread_info->thread_num);
+ fd[i] = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
+ ret = hos_write(fd[i], buff, buff_len, thread_info->thread_num);
if (ret == HOS_CLIENT_OK)
{
success_cnt++;
}else
{
- printf("error code:%d, thread_id:%d\n", ret, thread_info->thread_num);
+ //printf("error code:%d, thread_id:%d\n", ret, thread_info->thread_num);
//break;
}
clock_gettime(CLOCK_MONOTONIC, &ttmp);
@@ -348,7 +347,13 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
}
}
- hos_close_fd(fd, thread_info->thread_num);
+ for (i = 0; i < test_times; i++)
+ {
+ if (fd[i] > 2)
+ {
+ hos_close_fd(fd[i], thread_info->thread_num);
+ }
+ }
return 0;
}
@@ -365,7 +370,7 @@ static void *put_object_thread(void *ptr)
char *buff = NULL;
char file_name[100][256];
struct stat s_buf;
- int test_times = 100;
+ int test_times = 1000;
buff = (char *)malloc(30 * 1024 * 1024);
if (buff == NULL)
diff --git a/example/performance/test.sh b/example/performance/test.sh
index 19a04113..16948150 100755
--- a/example/performance/test.sh
+++ b/example/performance/test.sh
@@ -10,7 +10,7 @@ size=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
num=0
-while((${num} < 37))
+while((${num} < 100))
do
#./HosClientPerformance -a ${size[$num]}
#echo "./HosClientPerformance -a ${size[$num]} -A -f ./file/100k.data"
@@ -19,7 +19,9 @@ do
#./HosClientPerformance -f ./file/${size[$num]}.data -F
#echo ./HosClientPerformance -a 100 -A -f ./file/100k.data -t ${size[$num]} -S 1024
#./HosClientPerformance -a 100 -A -f ./file/100k.data -t ${size[$num]} -S 1024
- echo ./HosClientPerformance -a 100 -A -f ./file/100k.data -S ${size[$num]} -t 32
- ./HosClientPerformance -a 100 -A -f ./file/100k.data -S ${size[$num]} -t 32
+ #echo ./HosClientPerformance -a 100 -A -f ./file/100k.data -S ${size[$num]} -t 32
+ #./HosClientPerformance -a 100 -A -f ./file/100k.data -S ${size[$num]} -t 32
+ echo ./HosClientPerformance -P1 -t32
+ ./HosClientPerformance -P1 -t32
let "num++"
done