网络程序——定时器

news2024/10/7 6:42:56

网络程序还有一种需要处理的常用事件——定时事件。服务器程序通常管理着众多定时事件,因此如何有效地组织这些定时事件,使之能在预期的时间点被触发且不影响服务器的主要逻辑,对于服务器的性能有着至关重要的影响。为此,我们要将每个定时事件分别封装成定时器,并使用某种容器类数据结构,比如链表、 排序链表和时间轮,将所有定时器串联起来,以实现对定时事件的统一管理。本章主要讨论的就是两种高效的管理定时器的容器:时间轮和时间堆。

定时是指在一段时间之后触发某段代码的机制,我们可以在这段代码中依次处理所有到期的定时器,Linux提供了三种定时方法,他们分别是:

  • socket选项SO_RCVTIMEO和SO_SNDTIMEO
  • SIGALRM信号
  • I/O复用系统调用的超时参数

socket选项SO_RCVTIMEO和SO_SNDTIMEO

socket选项SO_RCVTIMEO和SO_SNDTIMEO,它们分别用来设置socket接收数据超时时间和发送数据超时时间。在程序中,我们可以根据系统调用(send、 sendmsg、recv、recvmsg、accept和connect)的返回值以及errno来判断超时时间是否已到,进而决定是否开始处理定时任务,选项SO_RCVTIMEO和SO_SNDTIMEO对这些系统调用的影响如下所示:

 下面以connect为例,说明程序中如何使用SO_SNDTIMEO选项来定时:

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
/*超时连接函数*/
int timeout_connect( const char* ip, int port, int time )
{
    int ret = 0;
    struct sockaddr_in address;
    bzero( &address, sizeof( address ) );
    address.sin_family = AF_INET;
    inet_pton( AF_INET, ip, &address.sin_addr );
    address.sin_port = htons( port );

    int sockfd = socket( PF_INET, SOCK_STREAM, 0 );
    assert( sockfd >= 0 );
    /*通过选项SO_RCVTIMEO和SO_SNDTIMEO所设置的超时时间的类型是timeval,
    这和select系统调用的超时参数类型相同*/
    struct timeval timeout;
    timeout.tv_sec = time;
    timeout.tv_usec = 0;
    socklen_t len = sizeof( timeout );
    //设置套接字属性:       通用套接字   发送超时
    ret = setsockopt( sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, len );
    assert( ret != -1 );

    ret = connect( sockfd, ( struct sockaddr* )&address, sizeof( address ) );
    if ( ret == -1 )
    {   /*超时对应的错误号是EINPROGRESS。
        下面这个条件如果成立,我们就可以处理定时任务了*/
        if( errno == EINPROGRESS )
        {
            printf( "connecting timeout\n" );
            return -1;
        }
        printf( "error occur when connecting to server\n" );
        return -1;
    }

    return sockfd;
}

int main( int argc, char* argv[] )
{
    if( argc <= 2 )
    {
        printf( "usage: %s ip_address port_number\n", basename( argv[0] ) );
        return 1;
    }
    const char* ip = argv[1];
    int port = atoi( argv[2] );

    int sockfd = timeout_connect( ip, port, 10 );
    if ( sockfd < 0 )
    {
        return 1;
    }
    return 0;
}

SIGALRM信号

由alarm和setitimer函数设置的实时闹钟一旦超时,将触发SIGALRM信号。因此,可以利用该信号的信号处理函数来处理定时任务。但是,如果要处理多个定时任务,就需要不断地触发 SIGALRM信号,并在其信号处理函数中执行到期的任务。一般而言, SIGALRM信号按照固定的频率生成,即由alarm或setitimer函数设置的定时周期T保持不变。如果某个定时任务的超时时间不是T的整数倍, 那么它实际被执行的时间和预期的时间将略有偏差。因此定时周期T反映了定时的精度。

先给出一种简单的定时器实现 ——基于升序链表的定时器

        定时器通常至少要包含两个成员:一个超时时间(相对时间或者绝对时间)和一个任务回调函数。有的时候还可能包含回调函数被执行时需要传入的参数,以及是否重启定时器等信息。如果使用链表作为容器来串联所有的定时器,则每个定时器还要包含指向下一个定时器的指针成员。进一步,如果链表是双向的,则每个定时器还需要包含指向前一个定时器的指针成员。

        下面代码实现了一个简单的升序定时器链表。升序定时器链表将其中的定时器按照超时时间做升序排序。

#ifndef LST_TIMER
#define LST_TIMER

#include <time.h>

#define BUFFER_SIZE 64
class util_timer;/*前向声明*/
/*用户数据结构:客户端socket地址、socket文件描述符、读缓存和定时器*/
struct client_data
{
    sockaddr_in address;
    int sockfd;
    char buf[ BUFFER_SIZE ];
    util_timer* timer;
};
/*定时器类*/
class util_timer
{
public:
    util_timer() : prev( NULL ), next( NULL ){}//构造函数

public:
   time_t expire; /*任务的超时时间,这里使用绝对时间*/
   void (*cb_func)( client_data* );/*任务回调函数*/
   /*回调函数处理的客户数据,由定时器的执行者传递给回调函数*/
   client_data* user_data;
   util_timer* prev;//指向前一个定时器
   util_timer* next;//指向下一个定时器
};
/*定时器链表,他是一个升序,双向链表,且带有头节点和尾结点*/
class sort_timer_lst
{
public:
    sort_timer_lst() : head( NULL ), tail( NULL ) {}
    /*链表被销毁时,删除其中所有的定时器*/
    ~sort_timer_lst()
    {
        util_timer* tmp = head;
        while( tmp )
        {
            head = tmp->next;
            delete tmp;
            tmp = head;
        }
    }
    /*将目标定时器timer添加到链表中*/
    void add_timer( util_timer* timer )
    {
        if( !timer )
        {
            return;
        }
        if( !head )
        {
            head = tail = timer;
            return; 
        }
        /*如果目标定时器的超时时间小于当前链表中所有定时器的超时时间,则把该定时器插入
        链表头部,作为链表新的头节点。否则就需要调用重载函数add_timer(util_timer*timer,util_timer*lst_head),
        把它插入链表中合适的位置,以保证链表的升序特性*/
        if( timer->expire < head->expire )
        {
            timer->next = head;
            head->prev = timer;
            head = timer;
            return;
        }
        add_timer( timer, head );
    }
    /*当某个定时任务发生变化时,调整对应的定时器在链表中的位置。
    这个函数只考虑被调整的定时器的超时时间延长的情况,即该定时器需要往链表的尾部移动*/
    void adjust_timer( util_timer* timer )
    {
        if( !timer )
        {
            return;
        }
        util_timer* tmp = timer->next;
        /*如果被调整的目标定时器处在链表尾部,或者该定时器新的超时值仍然小于其下一个
        定时器的超时值,则不用调整*/
        if( !tmp || ( timer->expire < tmp->expire ) )
        {
            return;
        }
        /*如果目标定时器是链表的头节点,则将该定时器从链表中取出并重新插入链表*/
        if( timer == head )
        {
            head = head->next;
            head->prev = NULL;
            timer->next = NULL;
            add_timer( timer, head );
        }
        /*如果目标定时器不是链表的头节点,则将该定时器从链表中取出,
        然后插入其原来所在位置之后的部分链表中*/
        else
        {
            timer->prev->next = timer->next;
            timer->next->prev = timer->prev;
            add_timer( timer, timer->next );
        }
    }
    /*将目标定时器timer从链表中删除*/
    void del_timer( util_timer* timer )
    {
        if( !timer )
        {
            return;
        }
        /*下面这个条件成立表示链表中只有一个定时器,即目标定时器*/
        if( ( timer == head ) && ( timer == tail ) )
        {
            delete timer;
            head = NULL;
            tail = NULL;
            return;
        }
        /*如果链表中至少有两个定时器,且目标定时器是链表的头结点,
        则将链表的头结点重置为原头节点的下一个节点,然后删除目标定时器*/
        if( timer == head )
        {
            head = head->next;
            head->prev = NULL;
            delete timer;
            return;
        }
        /*如果链表中至少有两个定时器,且目标定时器是链表的尾结点,
        则将链表的尾结点重置为原尾节点的前一个节点,然后删除目标定时器*/
        if( timer == tail )
        {
            tail = tail->prev;
            tail->next = NULL;
            delete timer;
            return;
        }
        /*如果目标定时器位于链表的中间,则把它前后的定时器串联起来,然后删除目标定时器*/
        timer->prev->next = timer->next;
        timer->next->prev = timer->prev;
        delete timer;
    }
    /*SIGALRM信号每次被触发就在其信号处理函数(如果使用统一事件源,则是主函数)中
    执行一次tick函数,以处理链表上到期的任务*/
    void tick()
    {
        if( !head )
        {
            return;
        }
        printf( "timer tick\n" );
        time_t cur = time( NULL );/*获得系统当前时间*/
        util_timer* tmp = head;
        /*从头结点开始依次处理每个定时器,直到遇到一个尚未到期的定时器,这就是定时器的核心逻辑*/
        while( tmp )
        {/*因为每个定时器都使用绝对时间作为超时值,所以我们可以把定时器的超时值和系统当
        前时间,比较以判断定时器是否到期*/
            if( cur < tmp->expire )
            {
                break;
            }
            /*调用定时器的回调函数,以执行定时任务*/
            tmp->cb_func( tmp->user_data );
            /*执行完定时器中的定时任务之后,就将它从链表中删除,并重置链表头结点*/
            head = tmp->next;
            if( head )
            {
                head->prev = NULL;
            }
            delete tmp;
            tmp = head;
        }
    }

private:
    /*一个重载的辅助函数,它被公有的add_timer函数和adjust_timer函数调用。该函
    数表示将目标定时器timer添加到节点lst_head之后的部分链表中*/
    void add_timer( util_timer* timer, util_timer* lst_head )
    {
        util_timer* prev = lst_head;
        util_timer* tmp = prev->next;
        /*遍历lst_head节点之后的部分链表,直到找到一个超时时间大于目标定时器的超时时
        间的节点,并将目标定时器插入该节点之前*/
        while( tmp )
        {
            if( timer->expire < tmp->expire )
            {
                prev->next = timer;
                timer->next = tmp;
                tmp->prev = timer;
                timer->prev = prev;
                break;
            }
            prev = tmp;
            tmp = tmp->next;
        }
        /*如果遍历完lst_head节点之后的部分链表,仍未找到超时时间大于目标定时器的超时
        时间的节点,则将目标定时器插入链表尾部,并把它设置为链表新的尾节点*/
        if( !tmp )
        {
            prev->next = timer;
            timer->prev = prev;
            timer->next = NULL;
            tail = timer;
        }
        
    }

private:
    util_timer* head;
    util_timer* tail;
};

#endif

其核心函数tick相当于一个心搏函数,它每隔一段固定的时间就执行一次,以检测并处理到期的任务。判断定时任务到期的依据是定时器的expire值小于当前的系统时间。

处理非活动连接

        现在考虑上述升序定时器链表的实际应用——处理非活动连接。服务器程序通常要定期处理非活动连接:给客户端发一个重连请求,或者关闭该连接,或者其他。Linux在内核中提供了对连接是否处于活动状态的定期检查机制,我们可以通过socket选项KEEPALIVE来激活它。不过使用这种方式将使得应用程序对连接的管理变得复杂。因此,我们可以考虑在应用层实现类似于KEEPALIVE的机制,以管理所有长时间处于非活动状态的连接。比如,下面代码清单利用alarm函数周期性地触发SIGALRM信号,该信号的信号处理函数利用管道通知主循环执行定时器链表上的定时任务——关闭非活动的连接。

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <pthread.h>
#include "lst_timer.h"

#define FD_LIMIT 65535
#define MAX_EVENT_NUMBER 1024
#define TIMESLOT 5

static int pipefd[2];
static sort_timer_lst timer_lst;
static int epollfd = 0;
/*利用上一个代码中的升序链表来管理定时器*/
int setnonblocking( int fd )
{
    int old_option = fcntl( fd, F_GETFL );
    int new_option = old_option | O_NONBLOCK;
    fcntl( fd, F_SETFL, new_option );
    return old_option;
}

void addfd( int epollfd, int fd )
{
    epoll_event event;
    event.data.fd = fd;
    event.events = EPOLLIN | EPOLLET;
    epoll_ctl( epollfd, EPOLL_CTL_ADD, fd, &event );
    setnonblocking( fd );
}

void sig_handler( int sig )
{
    int save_errno = errno;
    int msg = sig;
    send( pipefd[1], ( char* )&msg, 1, 0 );
    errno = save_errno;
}

void addsig( int sig )
{
    struct sigaction sa;
    memset( &sa, '\0', sizeof( sa ) );
    sa.sa_handler = sig_handler;
    sa.sa_flags |= SA_RESTART;
    sigfillset( &sa.sa_mask );
    assert( sigaction( sig, &sa, NULL ) != -1 );
}

void timer_handler()
{
    /*定时处理任务,实际上就是调用tick函数*/
    timer_lst.tick();
    /*因为一次alarm调用只会引起一次SIGALRM信号,所以我们要重新定时,以不断触发SIGALRM信号*/
    alarm( TIMESLOT );
}
/*定时器回调函数,它删除非活动连接socket上的注册事件,并关闭之*/
void cb_func( client_data* user_data )
{
    epoll_ctl( epollfd, EPOLL_CTL_DEL, user_data->sockfd, 0 );
    assert( user_data );
    close( user_data->sockfd );
    printf( "close fd %d\n", user_data->sockfd );
}

int main( int argc, char* argv[] )
{
    if( argc <= 2 )
    {
        printf( "usage: %s ip_address port_number\n", basename( argv[0] ) );
        return 1;
    }
    const char* ip = argv[1];
    int port = atoi( argv[2] );

    int ret = 0;
    struct sockaddr_in address;
    bzero( &address, sizeof( address ) );
    address.sin_family = AF_INET;
    inet_pton( AF_INET, ip, &address.sin_addr );
    address.sin_port = htons( port );

    int listenfd = socket( PF_INET, SOCK_STREAM, 0 );
    assert( listenfd >= 0 );

    ret = bind( listenfd, ( struct sockaddr* )&address, sizeof( address ) );
    assert( ret != -1 );

    ret = listen( listenfd, 5 );
    assert( ret != -1 );

    epoll_event events[ MAX_EVENT_NUMBER ];
    int epollfd = epoll_create( 5 );
    assert( epollfd != -1 );
    addfd( epollfd, listenfd );

    ret = socketpair( PF_UNIX, SOCK_STREAM, 0, pipefd );
    assert( ret != -1 );
    setnonblocking( pipefd[1] );
    addfd( epollfd, pipefd[0] );

    // 设置信号处理函数
    addsig( SIGALRM );
    addsig( SIGTERM );
    bool stop_server = false;

    client_data* users = new client_data[FD_LIMIT]; 
    bool timeout = false;
    alarm( TIMESLOT );/*定时*/

    while( !stop_server )
    {
        int number = epoll_wait( epollfd, events, MAX_EVENT_NUMBER, -1 );
        if ( ( number < 0 ) && ( errno != EINTR ) )
        {
            printf( "epoll failure\n" );
            break;
        }
    
        for ( int i = 0; i < number; i++ )
        {
            int sockfd = events[i].data.fd;
            /*处理新到的客户链接*/
            if( sockfd == listenfd )
            {
                struct sockaddr_in client_address;
                socklen_t client_addrlength = sizeof( client_address );
                int connfd = accept( listenfd, ( struct sockaddr* )&client_address, &client_addrlength );
                addfd( epollfd, connfd );
                users[connfd].address = client_address;
                users[connfd].sockfd = connfd;
                /*创建定时器,设置其回调函数与超时时间,然后绑定定时器与用户数据,
                最后将定时器添加到链表timer_lst中*/
                util_timer* timer = new util_timer;
                timer->user_data = &users[connfd];
                timer->cb_func = cb_func;
                time_t cur = time( NULL );
                timer->expire = cur + 3 * TIMESLOT;
                users[connfd].timer = timer;
                timer_lst.add_timer( timer );
            }
            /*处理信号*/
            else if( ( sockfd == pipefd[0] ) && ( events[i].events & EPOLLIN ) )
            {
                int sig;
                char signals[1024];
                ret = recv( pipefd[0], signals, sizeof( signals ), 0 );
                if( ret == -1 )
                {
                    // handle the error
                    continue;
                }
                else if( ret == 0 )
                {
                    continue;
                }
                else
                {
                    for( int i = 0; i < ret; ++i )
                    {
                        switch( signals[i] )
                        {
                            case SIGALRM:
                            {
                            /*用timeout变量标记有定时任务需要处理,但不立即处理定时任务。
                            这是因为定时任务的优先级不是很高,我们优先处理其他更重要的任务*/
                                timeout = true;
                                break;
                            }
                            case SIGTERM:
                            {
                                stop_server = true;
                            }
                        }
                    }
                }
            }
            /*处理客户连接上接收到的数据*/
            else if(  events[i].events & EPOLLIN )
            {
                memset( users[sockfd].buf, '\0', BUFFER_SIZE );
                ret = recv( sockfd, users[sockfd].buf, BUFFER_SIZE-1, 0 );
                printf( "get %d bytes of client data %s from %d\n", ret, users[sockfd].buf, sockfd );
                util_timer* timer = users[sockfd].timer;
                if( ret < 0 )
                {/*如果发生读错误,则关闭连接,并移除其对应的定时器*/
                    if( errno != EAGAIN )
                    {
                        cb_func( &users[sockfd] );
                        if( timer )
                        {
                            timer_lst.del_timer( timer );
                        }
                    }
                }
                else if( ret == 0 )
                {/*如果对方已经关闭连接,则我们也关闭连接,并移除对应的定时器*/
                    cb_func( &users[sockfd] );
                    if( timer )
                    {
                        timer_lst.del_timer( timer );
                    }
                }
                else
                {
                    /*如果某个客户连接上有数据可读,则我们要调整该连接对应的定时器,
                    以延迟该连接被关闭的时间*/
                    if( timer )
                    {
                        time_t cur = time( NULL );
                        timer->expire = cur + 3 * TIMESLOT;
                        printf( "adjust timer once\n" );
                        timer_lst.adjust_timer( timer );
                    }
                }
            }
            else
            {
                // others
            }
        }
        /*最后处理定时事件,因为I/O事件有更高的优先级。
        当然,这样做将导致定时任务不能精确地按照预期的时间执行*/
        if( timeout )
        {
            timer_handler();
            timeout = false;
        }
    }

    close( listenfd );
    close( pipefd[1] );
    close( pipefd[0] );
    delete [] users;
    return 0;
}

I/O复用系统调用的超时参数

        ·Linux下的3组I/O复用系统调用都带有超时参数,因此它们不仅能统一处理信号和I/O事件,也能统一处理定时事件。但是由于I/O复用系统调用可能在超时时间到期之前就返回,所以如果我们要利用它们来定时,就需要不断更新定时参数以反映剩余的时间, 如下面代码所示:

#define TIMEOUT 5000
int timeout=TIMEOUT;
time_t start=time(NULL);
time_t end=time(NULL);
while(1)
{
    printf("the timeout is now%d mil-seconds\n",timeout);
    start=time(NULL);
    int number=epoll_wait(epollfd,events,MAX_EVENT_NUMBER,timeout);
    if((number<0)&&(errno!=EINTR))
        {
            printf("epoll failure\n");
            break;
        }
    /*如果epoll_wait成功返回0,则说明超时时间到,此时便可处理定时任务,并重置定时时间*/
    if(number==0)
    {
        timeout=TIMEOUT;
        continue;
    }
    end=time(NULL);
    /*如果epoll_wait的返回值大于0,则本次epoll_wait调用持续的时间是(endstart)*1000 ms,我们需要将定时时间timeout减去这段时间,以获得下次epoll_wait调用的超时参数*/
    timeout-=(end-start)*1000;
/*重新计算之后的timeout值有可能等于0,说明本次epoll_wait调用返回时,不仅有文件描述符就绪,而且其超时时间也刚好到达,此时我们也要处理定时任务,并重置定时时间*/
    if(timeout<=0)
    {
        timeout=TIMEOUT;
    }
    //handle connections
}

高性能定时器

时间轮与时间堆。详细介绍建议看pdf介绍。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/692316.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

递归 到底应该怎么理解?怎么写递归的代码

今天和大家一起来讨论一下递归&#xff1a; 我们尽可能使按照解题的思路来讨论递归&#xff0c;对于这个在计算机内部具体是怎样实现的&#xff0c;我们不做深入讨论&#xff0c;这里仅仅是简单的讨论一下&#xff1a; 求1 ~ n序列的和&#xff1a;1 2 3 ... n&#xff1…

pwn学习day1——ELF文件结构

0x01 介绍 ELF&#xff08;Executable and Linkable Format&#xff09;是一种常见的可执行文件和共享库格式&#xff0c;其结构如下&#xff1a; ELF header&#xff1a;包含了 ELF 文件的基本属性信息。Program header table&#xff1a;描述了程序在内存中的加载情况&…

Gogs私服搭建

1. Gogs介绍 官网地址&#xff1a;https://gogs.io 文档地址&#xff1a;https://gogs.io/docs Gogs&#xff0c;全称为Go Git Service&#xff0c;是一个基于 Go 语言开发的Git服务。它提供了一个类似于GitHub的界面和功能&#xff0c;允许您在自己的服务器上搭建私有的Git仓库…

幂律智能联合智谱AI发布千亿参数级法律垂直大模型PowerLawGLM

前言 2023年是当之无愧的“大模型之年”&#xff0c;据瑞银集团的一份报告显示&#xff0c;ChatGPT推出仅仅两个月后&#xff0c;月活用户已经突破了1亿&#xff0c;成为史上用户增长速度最快的消费级应用程序。 在炙热的大模型赛道里&#xff0c;基于中文大模型的发布也是层…

二叉树OJ题:LeetCode--104.二叉树的最大深度

朋友们、伙计们&#xff0c;我们又见面了&#xff0c;本期来给大家解读一下LeetCode中第104道二叉树OJ题&#xff0c;如果看完之后对你有一定的启发&#xff0c;那么请留下你的三连&#xff0c;祝大家心想事成&#xff01; 数据结构与算法专栏&#xff1a;数据结构与算法 个 人…

SAP从入门到放弃系列之工艺路线-子工序-Part2

文章目录 概述使用场景子工序内容1、 维护工序控制码2、维护子工序的工资类型3、作业标准值4、用户定义字段5、通过维护子工序的作业类型数据后&#xff0c;点击汇总标准值&#xff0c;工序的作业类型值可以通过子工序进行累计6、可以设置子工序是否带入生产订单 注意事项&…

selenium通过xpath定位text换行的元素

DOM元素&#xff08;该元素是换行的&#xff0c;不能通过普通xpath定位&#xff09;&#xff1a; 可使用下面xpath定位该div //div[./text()/following-sibling::text()"点" and ./text()"5"] 解释一下就是&#xff1a;定位“子节点的text是[5] 且 子节点…

自然语言处理(概念)

1、 RNN模型简介 1.2传统RNN模型 2、LSTM模型 3、GRU模型 5、注意力机制 6、人名分类器 7 、BERT 8、Transformer 的结构是什么样子的&#xff1f; 各个子模块有什么作用&#xff1f; 8.1 Encoder模块 8.2 Decoder模块 8.3 Transformer 结构中的Decoder端具体输入是什么&#…

C# wpf 附加属性实现任意控件拖动调整大小

摘自这里 https://blog.csdn.net/u013113678/article/details/121719278 调试效果如下 using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Syst…

vue修改数据后页面不重新渲染

使用vue&#xff0c;遇到几次修改了对象的属性后&#xff0c;页面并不重新渲染 一、直接添加属性的问题 <template><div><p v-for"(value,key) in item" :key"key">{{ value }}</p><button click"addProperty">…

【Linux】在Ubuntu下部署nginx——nginx的负载均衡

介绍 这里是小编成长之路的历程&#xff0c;也是小编的学习之路。希望和各位大佬们一起成长&#xff01; 以下为小编最喜欢的两句话&#xff1a; 要有最朴素的生活和最遥远的梦想&#xff0c;即使明天天寒地冻&#xff0c;山高水远&#xff0c;路远马亡。 一个人为什么要努力&a…

vs中的一些编码问题

1. 基本概念 文件编码格式 首先vs中编辑&#xff0c;保存文件实际上也是将文件内容以一定的编码格式存储。对于中文字符串 string s "一"; 按不同的编码格式保存后&#xff0c;通过16进制文件查看器&#xff0c;可以看到中文的编码是能对应上的。 开放高级保存…

select和pselect的关于信号打断的实验

select和pslect的man手册 SELECT(2) Linux Programmers Manual SELECT(2)NAMEselect, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O …

【HDFS实战】HDFS联合(联邦)集群的发展史

HDFS联合集群的发展史 文章目录 HDFS联合集群的发展史HDFS原始架构方案一 HDFS Federation方案二 ViewFs方案三 HDFS Router-based Federation常用命令常用配置RPC serverConnection to the NamenodesAdmin serverHTTP ServerState StoreRoutingNamenode monitoring 版本相关is…

nestJS打印多层对象以及铺平金额类型

console.dir(ret, { depth: 3 }); 金额是Decimal类型不好显示 Logger.verbose(JSON.stringify(ret, null, 2)); 利用JSON.stringify参数格式化 null: 不对数据进行提取&#xff0c; 2&#xff1a;缩进两个空格&#xff0c; 效果是直接帮忙平铺金额对象

java.lang.IllegalStateException Unable to find a @SpringBootConfiguration代码报错

文章目录 一. 问题场景二. 报错原因三. 解决方案 一. 问题场景 使用idea基于springBoot的项目进行单元测试时&#xff0c;出现异常&#xff0c;如下所示&#xff1a; Test ignored.java.lang.IllegalStateException: Unable to find a SpringBootConfiguration, you need to …

【电源专题】案例:电池保护芯片有是否能向0V电池充电的功能的区别

本案例发生在实际的工作之中。案例是这样的,有些产品因为各种原因没有按规范将电池与设备断开,而是插入机器(存在1mA的静态功耗)中并存放在仓库里2年后发现产品无法开机使用,并且电池无法充电。更换新的电池后运行正常,所以认定为是电池的问题。 可是为什么电池无法充电呢…

学妹:怎样才能设计出优秀的测试用例?

这篇文章我们主要聊一下测试工程师最通用的也是最根本的技能&#xff0c;测试用例的设计能力。 测试用例 测试用例是通过使用在测试计划中确定的测试技术&#xff0c;对于已确定的测试条件进行逐步推敲&#xff0c;精炼而设计出来的重点说明如何具体操作产生何种结果的文档。…

(免费分享)基于springboot,vue高校就业系统

管理员&#xff1a;10086/123 学生&#xff1a;10087/123 企业&#xff1a;10070/123 辅导员&#xff1a;10090/123 项目描述 高校就业管理系统 学生 : 个人信息、查看企业岗位信息、简历信息管理、我的应聘 辅导员 : 学生信息管理、三方协议书审核、查看班级就业统计信息 企…

App启动流程分析(一)

一、App启动涉及到的三个进程 1、Launcher进程&#xff1a;负责接收用户点击屏幕的事件&#xff0c;它其实就是一个Activity&#xff0c;屏幕上的各种Icon就是这个Activity中的Button&#xff0c;当点击Icon时&#xff0c;会触发启动App的流程。 2、SystemServer进程&#xff…