free_queue support parameter: need_shrink and set task->shrinked

use_iouring
YuQing 2025-10-03 21:03:31 +08:00
parent 7973d81b69
commit d5dbe3d030
3 changed files with 35 additions and 22 deletions

View File

@ -1,6 +1,7 @@
Version 1.81 2025-09-27 Version 1.81 2025-10-03
* support Linux io_uring * support Linux io_uring
* free_queue support parameter: need_shrink and set task->shrinked
Version 1.80 2025-09-10 Version 1.80 2025-09-10
* getIpaddrByNameEx: IPv4 has priority over IPv6 * getIpaddrByNameEx: IPv4 has priority over IPv6

View File

@ -59,11 +59,11 @@ static int task_alloc_init(struct fast_task_info *task,
} }
int free_queue_init_ex2(struct fast_task_queue *queue, const char *name, int free_queue_init_ex2(struct fast_task_queue *queue, const char *name,
const bool double_buffers, const int max_connections, const bool double_buffers, const bool need_shrink,
const int alloc_task_once, const int min_buff_size, const int max_connections, const int alloc_task_once,
const int max_buff_size, const int padding_size, const int min_buff_size, const int max_buff_size,
const int arg_size, TaskInitCallback init_callback, const int padding_size, const int arg_size,
void *init_arg) TaskInitCallback init_callback, void *init_arg)
{ {
#define MAX_DATA_SIZE (256 * 1024 * 1024) #define MAX_DATA_SIZE (256 * 1024 * 1024)
int alloc_once; int alloc_once;
@ -123,6 +123,7 @@ int free_queue_init_ex2(struct fast_task_queue *queue, const char *name,
} }
queue->double_buffers = double_buffers; queue->double_buffers = double_buffers;
queue->need_shrink = need_shrink;
queue->min_buff_size = aligned_min_size; queue->min_buff_size = aligned_min_size;
queue->max_buff_size = aligned_max_size; queue->max_buff_size = aligned_max_size;
queue->padding_size = aligned_padding_size; queue->padding_size = aligned_padding_size;
@ -183,16 +184,23 @@ void free_queue_push(struct fast_task_info *task)
task->send.ptr->length = 0; task->send.ptr->length = 0;
task->send.ptr->offset = 0; task->send.ptr->offset = 0;
task->req_count = 0; task->req_count = 0;
if (task->send.ptr->size > task->free_queue->min_buff_size) {//need thrink if (task->free_queue->need_shrink && task->send.
_realloc_buffer(task->send.ptr, task->free_queue->min_buff_size, false); ptr->size > task->free_queue->min_buff_size)
{ //need thrink
_realloc_buffer(task->send.ptr, task->free_queue->
min_buff_size, false);
task->shrinked = true;
} }
if (task->free_queue->double_buffers) { if (task->free_queue->double_buffers) {
task->recv.ptr->length = 0; task->recv.ptr->length = 0;
task->recv.ptr->offset = 0; task->recv.ptr->offset = 0;
if (task->recv.ptr->size > task->free_queue->min_buff_size) { if (task->free_queue->need_shrink && task->recv.
ptr->size > task->free_queue->min_buff_size)
{
_realloc_buffer(task->recv.ptr, task->free_queue-> _realloc_buffer(task->recv.ptr, task->free_queue->
min_buff_size, false); min_buff_size, false);
task->shrinked = true;
} }
} }

View File

@ -140,6 +140,7 @@ struct fast_task_info
volatile uint8_t notify; volatile uint8_t notify;
} nio_stages; //stages for network IO } nio_stages; //stages for network IO
volatile int8_t canceled; //if task canceled volatile int8_t canceled; //if task canceled
volatile int8_t shrinked; //if task shrinked, since V1.0.81
volatile int reffer_count; volatile int reffer_count;
int pending_send_count; int pending_send_count;
int64_t req_count; //request count int64_t req_count; //request count
@ -169,6 +170,7 @@ struct fast_task_queue
int block_size; int block_size;
bool malloc_whole_block; bool malloc_whole_block;
bool double_buffers; //if send buffer and recv buffer are independent bool double_buffers; //if send buffer and recv buffer are independent
bool need_shrink;
struct fast_mblock_man allocator; struct fast_mblock_man allocator;
TaskInitCallback init_callback; TaskInitCallback init_callback;
void *init_arg; void *init_arg;
@ -180,22 +182,22 @@ extern "C" {
#endif #endif
int free_queue_init_ex2(struct fast_task_queue *queue, const char *name, int free_queue_init_ex2(struct fast_task_queue *queue, const char *name,
const bool double_buffers, const int max_connections, const bool double_buffers, const bool need_shrink,
const int alloc_task_once, const int min_buff_size, const int max_connections, const int alloc_task_once,
const int max_buff_size, const int padding_size, const int min_buff_size, const int max_buff_size,
const int arg_size, TaskInitCallback init_callback, const int padding_size, const int arg_size,
void *init_arg); TaskInitCallback init_callback, void *init_arg);
static inline int free_queue_init_ex(struct fast_task_queue *queue, static inline int free_queue_init_ex(struct fast_task_queue *queue,
const char *name, const bool double_buffers, const char *name, const bool double_buffers,
const int max_connections, const int alloc_task_once, const bool need_shrink, const int max_connections,
const int min_buff_size, const int max_buff_size, const int alloc_task_once, const int min_buff_size,
const int arg_size) const int max_buff_size, const int arg_size)
{ {
const int padding_size = 0; const int padding_size = 0;
return free_queue_init_ex2(queue, name, double_buffers, max_connections, return free_queue_init_ex2(queue, name, double_buffers, need_shrink,
alloc_task_once, min_buff_size, max_buff_size, padding_size, max_connections, alloc_task_once, min_buff_size, max_buff_size,
arg_size, NULL, NULL); padding_size, arg_size, NULL, NULL);
} }
static inline int free_queue_init(struct fast_task_queue *queue, static inline int free_queue_init(struct fast_task_queue *queue,
@ -204,9 +206,11 @@ static inline int free_queue_init(struct fast_task_queue *queue,
{ {
const char *name = ""; const char *name = "";
const bool double_buffers = false; const bool double_buffers = false;
const bool need_shrink = true;
const int arg_size = 0; const int arg_size = 0;
return free_queue_init_ex(queue, name, double_buffers, max_connections, return free_queue_init_ex(queue, name, double_buffers,
alloc_task_once, min_buff_size, max_buff_size, arg_size); need_shrink, max_connections, alloc_task_once,
min_buff_size, max_buff_size, arg_size);
} }
static inline void free_queue_set_release_callback( static inline void free_queue_set_release_callback(