There is an interface with two addresses: The primary address and the standby address. How can I determine if a server slows down and automatically switches to the next server?

Source: Internet
Author: User
How can I write a program to automatically determine whether another server is slow? They have two interface addresses located on two different servers. How can I use the program to automatically determine whether a server is slow, automatically switch to the request link on the next server ??? I use php to write a program. How can I write a program to automatically judge whether another server slows down? They have two interface addresses located on two different servers, how can I use a program to automatically determine if a server slows down and automatically switch to the request link on the next server ??? Programs written in php

Reply content:

How can I write a program to automatically determine whether another server is slow? They have two interface addresses located on two different servers. How can I use the program to automatically determine whether a server is slow, automatically switch to the request link on the next server ??? Programs written in php

It is strange that this function (similar to Server Load balancer) needs to be implemented on the client side (that is, your program.

Two suggestions:

  1. Communicate with the service provider to see if they can.

  2. If you can only do it on your own, we recommend that you create a program similar to the Gateway. The main logic is very simple. You can receive http requests from php and forward them to the first server by default, if it times out (a time that you think is slow), it will be forwarded to the next server. You can also write such logic in php (encapsulate an http client and try to isolate it from the business logic ).

Hope to help you. Good luck.

Device: Server A, server B, and reverse proxy server C
The AB server processes data.
Server C processes requests.

The following are some reverse proxy configurations. Optional.

Client_max_body_size 10 m; # maximum number of bytes allowed for client requests per file
Client_body_buffer_size 128 k; # maximum number of bytes for the buffer proxy to buffer client requests,
Proxy_connect_timeout 90; # timeout for nginx connection to backend servers (proxy connection timeout)
Proxy_send_timeout 90; # backend server data return time (proxy sending timeout)
Proxy_read_timeout 90; # response time of the backend server after successful connection (proxy receiving timeout)
Proxy_buffer_size 4 k; # Set the buffer size for the proxy server (nginx) to save user header information
Proxy_buffers 4 32 k; # proxy_buffers buffer, the average web page is less than 32 k settings
Proxy_busy_buffers_size 64 k; # buffer size under high load (proxy_buffers * 2)

1. Load Balancing is done for the two servers, or using other tools to remotely view the single server load during Long ping;
2. If a business flow requires two servers to participate in step-by-step, please reverse proxy one of them; all network requests use the same server to allocate servers according to different business flow steps of the user; for example: A is responsible for user step 1, B is responsible for user Step 2; Step 1 is light load, so we have A solution: A both directly processes the backend and the AB reverse proxy of the two servers; when the user is in step 1, the load is in server A, and when the user is in load 2, the load is in server B + Part A; in this way, the communication between the server B and the server B can be implemented in A local connection, while the user can only see server;

PS: if the load on the AB server is estimated to be heavy, we recommend that you add the server C as "miserable uncle" suggests;

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.