There is an interface, there are two addresses, one is the primary address, and the other is an alternate address, then how can I tell if a server slows down, automatically switch to the next server

Source: Internet
Author: User
How do I write a program automatically judge, other people's server is slow, they have two interface address, located in two different servers, then, how can I use the program to automatically determine a server is slow, automatically switch to the next server to request a link??? I use PHP to write programs

Reply content:

How do I write a program automatically judge, other people's server is slow, they have two interface address, located in two different servers, then, how can I use the program to automatically determine a server is slow, automatically switch to the next server to request a link??? I use PHP to write programs

It's strange that this feature (like load balancing) needs to be done on the client side (that is, your program).

Two recommendations:

    1. Communicate with the service party to see if they can do it.

    2. If you can only do it, it is recommended to do a gateway-like program, the main logic is very simple, to receive your PHP HTTP request, the default forwarding to the first server, if the time-out (one you think it means that it is relatively slow), then forward to the next server. You can also write such logic in PHP (encapsulate an HTTP client, and try to separate it from the business logic).

I hope I can help you. Good luck.

Device: A server, b server, c reverse proxy server
AB server to do data processing.
C Server for request processing.

The following are some of the reverse proxy configurations, optional.

Client_max_body_size 10m; #允许客户端请求的最大单文件字节数
Client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
Proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间 (proxy connection timed out)
Proxy_send_timeout 90; #后端服务器数据回传时间 (proxy send timeout)
Proxy_read_timeout 90; #连接成功后, back-end server response time (proxy receive timeout)
Proxy_buffer_size 4k; #设置代理服务器 (nginx) buffer size for saving user header information
Proxy_buffers 4 32k; #proxy_buffers缓冲区, the average Web page is set below 32k
Proxy_busy_buffers_size 64k; #高负荷下缓冲大小 (proxy_buffers*2)

1, the same as two load balancer, or use the ping long goods use other tools remote to view the single load;
2, if a business flow requires a two-step server to participate in a single step, please put one of the reverse proxy another; All network requests use the same server to assign servers according to user's different business flow steps, for example: A is responsible for user step 1,b is responsible for user Step 2, Step 1 is lighter, then we have to plan: A direct processing of the back end, and AB two server reverse proxy; The user is at step 1 when the load is at server A, the user is at load 2, the load is in the Server B + Part A, so that the AB two server communication can be done within a local connection, and the user can only see Server A;

PS: If the AB server load estimates will be very heavy, then the proposal according to "miserable Uncle" recommendation, join server C;

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.