Http-Netty-Rpc-Service Systems

 20190823rpc system change log
https://github.com/KouReal/Rpc-Netty-Registry/tree/master
will httptask httpserver module removed, call ctx invokewithfuture of rpcclient the call of rpcproxy directly httpserverhandler of writeandflush ,, this series the calling process is not blocked, in addition to first call a service created rpcclient is blocked cpu, after which on the whole performed within the thread does not participate io network transmission.
Why should we get rid of httptask, because httptask is thread, means that every time a request is received from httpserver will create a httptask thread, and this thread will httptask the future according to their own waitting, parknonos, but too many threads can not be created, in particular, and increase the number of requests is not proportional, because the thread switch back and forth would be wasted, but if you use the thread pool to deal with the request, does not work, because of the limited number of thread pool, and wait for the network time-consuming io bound to the thread in the thread pool, and this traditional bio problem is the same, the thread pool will not be able to meet the high concurrent requests, in short, highly concurrent threads must not mean much, but the thread is the need to make full use of, rather than pursuing a parallel concurrency, and so is the actual physical cpu parallel the ability to decide, in the dual-core cpu, usually dual-core can support parallel 4 threads, so the number of workergroup default thread netty is 4, although only four threads, but if you can do it four threads fully utilized in parallel, not blocking does not wait for the network to read and write io, we can achieve the requested amount Big effect.

Note here that the bio nio refers to a network or the socket io, io for the disk is useless, because the network io asynchronously read and write through cache buffer, then the application layer to the polling processing is completed io channel can without waiting for network transmission delay, since you can use to get ready, to achieve non-blocking.

 

 

 



And magnetic disk io must copy the kernel mode and user mode, will need to be involved and cpu and memory disks, such statements need to select the database fields comparison, the compare operation requires involvement cpu internal logical unit.

As to discover registryclient the thread must block the request, because the request to initiate rpcproxy discover only get remote address of the service in order to continue to create rpcclient, this request will not be too frequent, are once and for all.

addservice request registryclient also needs to block, because only registered to receive normalconfig centers continue to set other configuration parameters like springboot environment, complete the creation of the bean, and only at startup before issuing the request.

 


In rpcserver need to create a thread pool to handle rpc request, the main thread pool to perform database read and write, read and write requests because they vary, some need a long time, some need short time, in order to balance the time and satisfy each request fair, use the appropriate size of the thread pool to handle the database to read and write, there is likely to be less time consuming tasks discharged to the forefront, according to the greedy algorithm optimal order problems, less time consuming tasks can be routed to the front to reduce the average waiting time here the use of fuzzy after multiple threads and approximate balance, but not precise enough, can improve over a period of time to accumulate more than one task to read and write the database, according to the type of io estimated time to sort and then walk through execution to achieve optimal efficiency. So this action is not involved in the io, and can be complicated by other aspects of the threads during collection io request.

The database is read-write disk is a disk io, this area can not achieve in this area can not achieve nio, performance is limited by the performance of the database, it is necessary to optimize the database, sub-library sub-table.

cpu utilization is a professional term that refers to the degree of intensity of work cpu, cpu io blocked by much, but the utilization rate does not rise, the purpose is to sufficiently high concurrent increase cpu utilization, do not let it wait for io or because io cpu caused frequent switching, wasted on things moot. So in the pursuit of the topic under high concurrency, cpu to pursue practical effect of high efficiency, high concurrent requests prefer to eat at least let Cpu, but do not give him respite or switch opportunities.

Greedy algorithm What is the principle?
Greedy (multiple optimal order problem)
quietly reading chase number: 54052016-04-22
Copyright: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source and this link statement.
This link: https: //blog.csdn.net/jingttkx/article/details/51221097
question:

N offers customers while waiting for a service, the customer service time i need to ti (1 <= i <= N) at a total of S can provide this service,

how to arrange the order of N services customers need to make the average the waiting time to a minimum? The average waiting time is equal to N number of customers waiting for service time divided by the total N.

Input:

The first line of two positive integers N and S represents the N S of customer service, the next customer service time required for the N

outputs:

the average waiting time, three decimal places.

Sample input:

10 2

56 is 12 is 1,991,000,234,335,599,812

Output Sample:

336.000



customer a customer waiting time n, s n-th customer service take drugs do service time averaging minimum waiting time (service time in ascending order)



#include <the iostream>
#include <algorithm>
#include <cstdio>
#include <CString>
#include <String>

the using namespace STD;
int A [1000];
int Ser [100]; // service customer waiting time window
int sum [100]; // sum of customer service window waiting time.
main int ()
{
    int n-, S;
    while(~scanf("%d%d",&n,&s))
    {
        for(int i=0;i<n;i++)
        {
         scanf("%d",&a[i]);
        }
        sort(a,a+n);
        memset(ser,0,sizeof(ser));
        memset(sum,0,sizeof(sum));
        int i=0;
        int j=0;
        while(i<n)
        {
            ser[j]+=a[i];
            sum[j]+=ser[j];
            i++,j++;
            if(j==s)
                j=0;

        }
        double t=0;
        for(int i=0;i<n;i++)
        {
            t+=sum[i];
        }
        t/=n;
        printf("%0.3lf\n",t);
    }
    return 0;

Guess you like

Origin www.cnblogs.com/CreatorKou/p/11402277.html