修改并增加新接口

This commit is contained in:
pengxuanzheng
2020-09-21 19:19:18 +08:00
parent a00d892928
commit eb41917cb2
22 changed files with 1916 additions and 106 deletions

BIN
example/data/100k.data Normal file

Binary file not shown.

BIN
example/data/10k.data Normal file

Binary file not shown.

BIN
example/data/1M.data Normal file

Binary file not shown.

BIN
example/data/1k.data Normal file

Binary file not shown.

BIN
example/data/2M.data Normal file

Binary file not shown.

BIN
example/data/3M.data Normal file

Binary file not shown.

BIN
example/data/4M.data Normal file

Binary file not shown.

15
example/data/test_size.sh Executable file
View File

@@ -0,0 +1,15 @@
#########################################################################
# File Name: test_times.sh
# Author: pxz
# Created Time: Mon 21 Sep 2020 04:43:35 PM CST
#########################################################################
#!/bin/bash
test_size=("1k" "10k" "100k" "1M" "2M" "3M" "4M")
num=0
while((${num} < 7))
do
./singleThread mybucket ${test_size[$num]}.data 1000
let "num++"
done

BIN
example/singleThread Executable file

Binary file not shown.

View File

@@ -3,34 +3,140 @@
> Author: pxz
> Created Time: Fri 11 Sep 2020 09:52:05 AM CST
************************************************************************/
extern "C"
{
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<time.h>
}
#include"../src/hos_client.h"
//#define test_times 10000
#define debuginfo (void)
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));
}
int file_to_buffer(const char *file, char *buffer, size_t *len)
{
FILE *fp = fopen(file, "r");
int num = 0;
*len = 0;
if (fp == NULL)
{
debuginfo("fopen file failed:%s\n", file);
return -1;
}
do{
num = fread(&buffer[*len], 1, 4096, fp);
if (num < 0)
{
return -1;
}
*len += num;
}while(num == 4096);
fclose(fp);
return 0;
}
void callback(bool result, const char *error, void *userdata)
{
//debuginfo("result : %s\n", result ? "true":"false");
if (result)
return ;
//debuginfo("error: %s\n", error);
//debuginfo("userdata:%s\n", (char *)userdata);
hos_close_fd(*(int *)userdata, 0);
return ;
}
int main(int argc, char *argv[])
{
if (argc != 4)
{
debuginfo("usege: singThread [bucket name] [object name]\n");
return -1;
}
struct timespec start, end;
size_t time;
int i = 0;
char *bucket = argv[1];
printf("hos_client_init start ...\n");
hos_client_handle handle = hos_client_init("http://192.168.44.12:9098/hos", "default", "default");
char *object = argv[2];
int test_times = atoi(argv[3]);
//int test_times = 10000;
//char *buf = (char *)malloc(1024 * 1024 * 4);
char buf[1024 * 1024 * 4];
size_t buf_size;
file_to_buffer(object, buf, &buf_size);
debuginfo("hos_client_init start ...\n");
hos_client_handle handle = hos_client_create("http://192.168.44.12:9098/hos/", "default", "default", 4);
if (handle == NULL)
{
printf("error:hos_client_handle\n");
debuginfo("error:hos_client_handle\n");
return -1;
}
printf("hos_client_init success ...");
debuginfo("hos_client_init success ... \n");
printf("hos_create_bucket start ... \n");
if(!hos_create_bucket(handle, bucket))
debuginfo("hos_create_bucket start ... \n");
if(hos_create_bucket(handle, bucket))
{
printf("hos_create_bucket failed ... \n");
debuginfo("hos_create_bucket failed ... \n");
return -1;
}
printf("hos_create_bucket success ... \n");
debuginfo("hos_create_bucket success ... \n");
printf("hos_upload_async start ...\n");
hos_upload_async(handle, bucket, "my-file.txt");
debuginfo("hos_verify_bucket start ... \n");
if(!hos_verify_bucket(handle, bucket))
{
debuginfo("hos_verify_bucket failed ... \n");
return -1;
}
debuginfo("hos_verify_bucket success ... \n");
//sleep(30);
hos_client_close(handle);
#if 1
int mode = FILE_MODE;
size_t fd = 0;
fd = hos_open_fd(handle, bucket, object, callback, (void *)&fd, 0, mode);
debuginfo("hos_upload_file start ...\n");
clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < test_times; i++)
{
hos_write(fd, 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
int mode = BUFF_MODE;
size_t fd = 0;
fd = hos_open_fd(handle, bucket, object, callback, (void *)&fd, 0, mode);
debuginfo("hos_upload_buf start ...\n");
clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < test_times; i++)
{
hos_write(fd, buf, buf_size, 0);
}
clock_gettime(CLOCK_MONOTONIC, &end);
time = calc_time(start, end);
time /= test_times;
printf("hos_upload_buf spent %llu ns\n", time);
debuginfo("hos_upload_buf end ...\n");
#endif
debuginfo("hos_client_close start ...\n");
hos_client_destory(handle);
debuginfo("hos_client_close end ...\n");
return 0;
}

View File

@@ -0,0 +1,115 @@
/*************************************************************************
> File Name: single_thread.cpp
> Author: pxz
> Created Time: Fri 11 Sep 2020 09:52:05 AM CST
************************************************************************/
extern "C"
{
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<time.h>
}
#include"../src/hos_client.h"
#define MAX_TEST_TIMES 10
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));
}
void callback(bool result, const char *error, void *userdata)
{
//printf("result : %s\n", result ? "true":"false");
if (result)
return ;
//printf("error: %s\n", error);
//printf("userdata:%s\n", (char *)userdata);
return ;
}
int main(int argc, char *argv[])
{
if (argc != 3)
{
printf("usege: singThread [bucket name] [object name]\n");
return -1;
}
struct timespec start, end;
size_t time;
int i = 0;
char *bucket = argv[1];
char *object = argv[2];
printf("hos_client_init start ...\n");
hos_client_handle handle = hos_client_create("http://192.168.44.12:9098/hos/", "default", "default", 4);
if (handle == NULL)
{
printf("error:hos_client_handle\n");
return -1;
}
printf("hos_client_init success ... \n");
printf("hos_create_bucket start ... \n");
if(hos_create_bucket(handle, bucket))
{
printf("hos_create_bucket failed ... \n");
return -1;
}
printf("hos_create_bucket success ... \n");
printf("hos_verify_bucket start ... \n");
if(!hos_verify_bucket(handle, bucket))
{
printf("hos_verify_bucket failed ... \n");
return -1;
}
printf("hos_verify_bucket success ... \n");
printf("hos_upload_file start ...\n");
#if 1
clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 0; i < MAX_TEST_TIMES; i++)
{
hos_upload_file(handle, bucket, object, callback, (void *)"this is userdata", 0);
}
clock_gettime(CLOCK_MONOTONIC, &end);
time = calc_time(start, end);
time /= MAX_TEST_TIMES;
printf("hos_upload_file spent %llu ns\n", time);
#if 0
for (i = 0; i < MAX_TEST_TIMES; i++)
{
hos_close_fd(i, 0);
}
#endif
printf("hos_upload_file end ...\n");
#else
const char *buf = "this is hos_upload_buf\n";
size_t buf_len = strlen(buf);
printf("hos_upload_buf start ...\n");
clock_gettime(CLOCK_MONOTONIC, &start);
for (i = 1; i <= MAX_TEST_TIMES; i++)
{
hos_upload_buf(handle, bucket, object, buf, buf_len, callback, (void *)"this is userdata", 0);
}
clock_gettime(CLOCK_MONOTONIC, &end);
time = calc_time(start, end);
time /= MAX_TEST_TIMES;
printf("hos_upload_buf spent %llu ns\n", time);
for (i = 1; i <= MAX_TEST_TIMES; i++)
{
hos_close_fd(i, 0);
}
printf("hos_upload_buf end ...\n");
#endif
printf("hos_client_close start ...\n");
hos_client_destory(handle);
printf("hos_client_close end ...\n");
return 0;
}

15
example/test_size.sh Executable file
View File

@@ -0,0 +1,15 @@
#########################################################################
# File Name: test_times.sh
# Author: pxz
# Created Time: Mon 21 Sep 2020 04:43:35 PM CST
#########################################################################
#!/bin/bash
test_size=("1k" "10k" "100k" "1M" "2M" "3M" "4M")
num=0
while((${num} < 7))
do
./singleThread mybucket ./data//${test_size[$num]}.data 1000
let "num++"
done

15
example/test_times.sh Executable file
View File

@@ -0,0 +1,15 @@
#########################################################################
# File Name: test_times.sh
# Author: pxz
# Created Time: Mon 21 Sep 2020 04:43:35 PM CST
#########################################################################
#!/bin/bash
test_times=(1, 10, 100, 1000, 10000)
num=0
while((${num} < 5))
do
./singleThread mybucket my-file.txt ${test_times[$num]}
let "num++"
done