Nginx IP cluster selection algorithm java

Source: Internet
Author: User

View Nginx source code, the Nginx IP selection algorithm into Java:

 Packagecom.csst.msm; Public classTest {/**     * @paramargs*/     Public Static voidMain (string[] args) {inthash = 89;//Initial value        intServernum = 2;//Number of servers        intaddrlen=3;//IPV4 Compute only the first 3 bytes        intp; int[] addr =New int[]{192,168,10,14};  for(inti=0;i<addrlen;i++) {//only the first 3 bytes are calculatedhash = (Hash*113+addr[i])% 6271; } P=hash%Servernum; System.out.println ("Selected server:" +p); //Weight Algorithm                int[] weights =New int[]{9,9}; intTotal_weight =weights[0]+weights[1]; intW =hash%Total_weight; intJ=0;  for(j=0;j<servernum;j++) {W-=Weights[j]; if(w<0)                 Break; } P=J; System.out.println ("By weight, select server:" +p); }}

From this code can be seen, run this code can see nginx according to IP Select the rules of the server.

Nginx IP cluster selection algorithm java

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.