Decreate http read buff's size for shared stack fiber mode.

This commit is contained in:
shuxin   zheng 2023-08-23 10:46:16 +08:00
parent 267e017340
commit 1705f9b56e
2 changed files with 26 additions and 31 deletions

View File

@ -39,11 +39,9 @@ static EPOLL_CTX *main_epoll_ctx = NULL;
static void main_epoll_end(void)
{
const char *myname = "main_epoll_end";
if (main_epoll_ctx != NULL) {
acl_msg_info("%s(%d), %s: close epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, main_epoll_ctx->epfd,
__FILE__, __LINE__, __FUNCTION__, main_epoll_ctx->epfd,
(unsigned long) main_epoll_ctx->tid,
(unsigned long) acl_pthread_self());
@ -59,11 +57,10 @@ static acl_pthread_once_t epoll_once = ACL_PTHREAD_ONCE_INIT;
static void thread_epoll_end(void *ctx)
{
const char *myname = "thread_epoll_end";
EPOLL_CTX *epoll_ctx = (EPOLL_CTX*) ctx;
acl_msg_info("%s(%d), %s: close epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, epoll_ctx->epfd,
__FILE__, __LINE__, __FUNCTION__, epoll_ctx->epfd,
(unsigned long) epoll_ctx->tid,
(unsigned long) acl_pthread_self());
@ -80,7 +77,6 @@ static void thread_epoll_once(void)
static EPOLL_CTX *thread_epoll_init(void)
{
const char *myname = "thread_epoll_init";
EPOLL_CTX *epoll_ctx = (EPOLL_CTX*) acl_mymalloc(sizeof(EPOLL_CTX));
if (acl_pthread_setspecific(epoll_key, epoll_ctx) != 0)
@ -90,7 +86,7 @@ static EPOLL_CTX *thread_epoll_init(void)
epoll_ctx->epfd = epoll_create(1);
if (epoll_ctx == NULL) {
acl_msg_error("%s(%d): epoll_create error: %s",
myname, __LINE__, acl_last_serror());
__FUNCTION__, __LINE__, acl_last_serror());
return NULL;
}
@ -100,12 +96,12 @@ static EPOLL_CTX *thread_epoll_init(void)
atexit(main_epoll_end);
#endif
acl_msg_info("%s(%d): %s, create epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, epoll_ctx->epfd,
__FILE__, __LINE__, __FUNCTION__, epoll_ctx->epfd,
(unsigned long) epoll_ctx->tid,
(unsigned long) acl_pthread_self());
} else {
acl_msg_info("%s(%d): %s, create epoll_fd: %d, tid: %lu, %lu",
__FILE__, __LINE__, myname, epoll_ctx->epfd,
__FILE__, __LINE__, __FUNCTION__, epoll_ctx->epfd,
(unsigned long) epoll_ctx->tid,
(unsigned long) acl_pthread_self());
}
@ -115,13 +111,11 @@ static EPOLL_CTX *thread_epoll_init(void)
static int thread_epoll_reopen(EPOLL_CTX *epoll_ctx)
{
const char *myname = "thread_epoll_reopen";
close(epoll_ctx->epfd);
epoll_ctx->epfd = epoll_create(1);
if (epoll_ctx->epfd == -1) {
acl_msg_error("%s(%d): epoll_create error: %s",
myname, __LINE__, acl_last_serror());
__FUNCTION__, __LINE__, acl_last_serror());
return -1;
}
return 0;
@ -129,7 +123,6 @@ static int thread_epoll_reopen(EPOLL_CTX *epoll_ctx)
int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
{
const char *myname = "acl_read_epoll_wait";
int ret, retried = 0;
EPOLL_CTX *epoll_ctx;
struct epoll_event ee, events[1];
@ -143,7 +136,7 @@ int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
epoll_ctx = thread_epoll_init();
if (epoll_ctx == NULL) {
acl_msg_error("%s(%d): thread_epoll_init error",
myname, __LINE__);
__FUNCTION__, __LINE__);
return -1;
}
}
@ -175,7 +168,7 @@ int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
}
acl_msg_error("%s(%d): epoll_ctl error: %s, fd: %d, "
"epfd: %d, tid: %lu, %lu", myname, __LINE__,
"epfd: %d, tid: %lu, %lu", __FUNCTION__, __LINE__,
acl_last_serror(), fd, epoll_ctx->epfd,
(unsigned long) epoll_ctx->tid,
(unsigned long) acl_pthread_self());
@ -197,7 +190,7 @@ int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
continue;
} else if (ret == EBADF || ret == EINTR) {
acl_msg_error("%s(%d): fd: %d, epfd: %d,"
" error: %s", myname, __LINE__, fd,
" error: %s", __FUNCTION__, __LINE__, fd,
epoll_ctx->epfd, acl_last_serror());
if (retried) {
@ -214,7 +207,7 @@ int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
}
acl_msg_error("%s(%d): epoll_wait error: %s, fd: %d,"
" epfd: %d, tid: %lu, %lu", myname, __LINE__,
" epfd: %d, tid: %lu, %lu", __FUNCTION__, __LINE__,
acl_last_serror(), fd, epoll_ctx->epfd,
(unsigned long) epoll_ctx->tid,
(unsigned long) acl_pthread_self());
@ -224,7 +217,7 @@ int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
/*
acl_msg_warn("%s(%d), %s: poll timeout: %s, fd: %d, "
"delay: %d, spent: %ld", __FILE__, __LINE__,
myname, acl_last_serror(), fd, delay,
__FUNCTION__, acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
*/
if (delay == 0) {
@ -241,7 +234,7 @@ int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
} else {
acl_msg_warn("%s(%d), %s: poll error: %s, fd: %d, "
"delay: %d, spent: %ld", __FILE__, __LINE__,
myname, acl_last_serror(), fd, delay,
__FUNCTION__, acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
ret = -1;
}
@ -253,7 +246,7 @@ int acl_read_epoll_wait(ACL_SOCKET fd, int delay)
ee.data.fd = fd;
if (epoll_ctl(epoll_ctx->epfd, EPOLL_CTL_DEL, fd, &ee) == -1) {
acl_msg_error("%s(%d): epoll_ctl error: %s, fd: %d, epfd: %d,"
" tid: %lu, %lu", myname, __LINE__, acl_last_serror(),
" tid: %lu, %lu", __FUNCTION__, __LINE__, acl_last_serror(),
fd, epoll_ctx->epfd, (unsigned long) epoll_ctx->tid,
(unsigned long) acl_pthread_self());
return -1;
@ -295,7 +288,6 @@ void acl_set_poll(acl_poll_fn fn)
int acl_read_poll_wait(ACL_SOCKET fd, int delay)
{
const char *myname = "acl_read_poll_wait";
struct pollfd fds;
time_t begin;
int left = delay;
@ -341,7 +333,7 @@ int acl_read_poll_wait(ACL_SOCKET fd, int delay)
}
/*
acl_msg_error("%s(%d), %s: poll error(%s), fd: %d",
__FILE__, __LINE__, myname,
__FILE__, __LINE__, __FUNCTION__,
acl_last_serror(), (int) fd);
*/
return -1;
@ -349,7 +341,7 @@ int acl_read_poll_wait(ACL_SOCKET fd, int delay)
/*
acl_msg_warn("%s(%d), %s: poll timeout: %s, fd: %d, "
"delay: %d, spent: %ld", __FILE__, __LINE__,
myname, acl_last_serror(), fd, delay,
__FUNCTION__, acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
*/
if (left > 0) {
@ -369,7 +361,7 @@ int acl_read_poll_wait(ACL_SOCKET fd, int delay)
if (fds.revents & (POLLHUP | POLLERR | POLLNVAL)) {
acl_msg_warn("%s(%d), %s: poll error: %s, "
"fd: %d, delay: %d, spent: %ld",
__FILE__, __LINE__, myname,
__FILE__, __LINE__, __FUNCTION__ ,
acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
return 0;
@ -377,7 +369,7 @@ int acl_read_poll_wait(ACL_SOCKET fd, int delay)
acl_msg_warn("%s(%d), %s: poll error: %s, fd: %d, "
"delay: %d, spent: %ld", __FILE__, __LINE__,
myname, acl_last_serror(), fd, delay,
__FUNCTION__, acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
return -1;
}
@ -392,7 +384,6 @@ static HANDLE __handle = NULL;
int acl_read_iocp_wait(ACL_SOCKET fd, int timeout)
{
const char *myname = "acl_read_iocp_wait";
OVERLAPPED *overlapped, *lpOverlapped;
DWORD recvBytes;
BOOL isSuccess;
@ -427,7 +418,7 @@ int acl_read_iocp_wait(ACL_SOCKET fd, int timeout)
if (ReadFile((HANDLE) fd, NULL, 0, &recvBytes, overlapped) == FALSE
&& acl_last_error() != ERROR_IO_PENDING) {
acl_msg_warn("%s(%d): ReadFile error(%s)",
myname, __LINE__, acl_last_serror());
__FUNCTION__, __LINE__, acl_last_serror());
return -1;
}
@ -467,7 +458,6 @@ void acl_set_select(acl_select_fn fn)
int acl_read_select_wait(ACL_SOCKET fd, int delay)
{
const char *myname = "acl_read_select_wait";
fd_set rfds, xfds;
struct timeval tv;
struct timeval *tp;
@ -480,7 +470,7 @@ int acl_read_select_wait(ACL_SOCKET fd, int delay)
#ifndef ACL_WINDOWS
if (FD_SETSIZE <= (unsigned) fd)
acl_msg_fatal("%s(%d), %s: descriptor %d does not fit "
"FD_SETSIZE %d", __FILE__, __LINE__, myname,
"FD_SETSIZE %d", __FILE__, __LINE__, __FUNCTION__,
(int) fd, FD_SETSIZE);
#endif
@ -528,14 +518,14 @@ int acl_read_select_wait(ACL_SOCKET fd, int delay)
}
#endif
acl_msg_error("%s(%d), %s: select error(%s), fd: %d",
__FILE__, __LINE__, myname,
__FILE__, __LINE__, __FUNCTION__,
acl_last_serror(), (int) fd);
return -1;
case 0:
/*
acl_msg_warn("%s(%d), %s: poll timeout: %s, fd: %d, "
"timeout: %d, spent: %ld", __FILE__, __LINE__,
myname, acl_last_serror(), fd, timeout,
__FUNCTION__, acl_last_serror(), fd, timeout,
(long) (time(NULL) - begin));
*/
if (delay == 0) {

View File

@ -88,7 +88,12 @@ static int hdr_ready(HTTP_HDR *hdr, const char *line, int dlen)
static int hdr_get(HTTP_HDR *hdr, ACL_VSTREAM *stream, int timeout)
{
/* 当使用协程共享栈时如果将此BUFF设的过大会增大共享栈的空间大小造成内存浪费 */
#ifdef HTTP_READ_BUF8192
char buf[8192];
#else
char buf[4912];
#endif
int ret;
stream->rw_timeout = timeout;