Story details the implementation of load balancing technology: from Tomcat to Nginx

Time:2019-9-11

What is load balancing?

Popularly speaking, it is the technology of decompressing servers in the environment of high concurrency and large data.

Load balancing is a problem that any Internet enterprise with a certain scale will consider. There are many load modes, which depend on hardware and software.

Today, let’s talk about how to load software.

You may have heard of different ways of loading, such as common technical frameworks such as nginx, dubbo, spring cloud and so on. As a software bull, have you considered the differences between these ways of loading?

Now Xiaoyuan will come to the imaginary case to talk about the commonly used load, I think you will certainly be helpful.

Talk about a Tomcat

Long, long ago, Xiaoyuan set up his own company, and made a shopping website – “Xiaoyuan Shopping Network”. At first, the structure was very simple. The traditional java development framework, a Tomcat container, after a month of day and night coding, it was completed and online.

One year later, the project was unexpectedly on fire. Every day, a large number of people came to buy dolls, clothes, cups and so on. Suddenly found a Tomcat is not sure, what to do? Two tomcats!

So the problem is that there are two Tomcats and several servers, but I only have one domain name. What should I do?

Story details the implementation of load balancing technology: from Tomcat to Nginx

Nginx debut

Nginx debut, through the inversion of the ape of a stick subroutine, the introduction of nginx in the project can solve the problem of concurrency, the research process is not simple, session how to share, how to configure configuration files, etc., said more is tears, anyway, at least completed the task, allowing two Tomcats to work together.

However, the online mall is becoming more and more popular. In less than two months, it was found that two Tomcats could not be solved. What should we do? Only more Tomcats can be integrated. Of course, Nginx integration has no problem with many tomcats. The architecture diagram is as follows:

Story details the implementation of load balancing technology: from Tomcat to Nginx

But…

To add Tomcat Xiaoyuan, I have to modify the configuration file nginx. conf. I can reload to make nginx work, but reload dog blood often has problems, and I have to restart it frequently.

Restart is a big trouble. My service can’t stop. The customers are shopping well. Suddenly they find that they can’t place orders and pay. Isn’t that very bad?

In fact, it’s also good. Although the customer friendliness is not good, Xiaoyuan usually works overtime at 3:00 a.m. to maintain it. Fortunately, it’s hard, but it’s barely acceptable.

Until one day…

A Nightmare Day

Xiaoyuan was taking a nap that day. For three volt days, the sun was shining high. He was banging in his sleep. The electricity was not stopped, but the nginx server was already smoking.

What should I do? That day, the server of nginx must have been reimbursed. It wasn’t long before customers’complaint calls came endlessly, which was just the last 10 minutes…

I can only rebuild a server. Fortunately, the server still has, but I forgot to back up everything in the configuration file. It took me a full hour to get the server ready in a hurry, or when the nginx configuration file is very skilled.

Although the problem has been solved, Xiaoyuan is still scolded by the investment manager, losing a lot of money in an hour, and complaints from customers are piling up.

What if this happens again in the future? I certainly remember backing up the configuration file, but it’s unacceptable to have nginx crash again.

Finally…

Nginx + keep alived Online

A nginx cluster is definitely not going to work, so I have to use two nginx clusters. One nginx smokes and the other nignx is waiting to be replaced. Is that all right?

Okay, so the overall architecture is as follows.

Story details the implementation of load balancing technology: from Tomcat to Nginx

Finally, such an architecture solves a big problem.

But there are also problems with this architecture. What are the problems? What does Dubbo, spring cloud, zookeeper really have to do with load?

Let me give you an example to relax, and then tell you a problem that most people will face.

A Problem Most People Will Face
You must feel the same about the following thing.

Zhang Cheng has been working for 2 years. Every project is overtime and completed with high quality. The salary is still less than 10,000 yuan. Many times, the leader always said oh oh oh, you know.

At lunch, he heard that a departing colleague had doubled his annual salary after he changed his job, which was 400,000 plus. At this time, he was shocked to understand that the problem is not his own, but that it is difficult to raise salary substantially in his current job.

You certainly want to get 400,000 + yearly salary quickly, don’t you?

Obviously, the Java Architect is your opportunity.

I understand that the whole industry is currently using micro-service technology, the shortage of talent is very serious, and the starting salary of ordinary micro-service development is also 15K/month.

There are many examples of getting high salaries through micro-service technology. We have a lot of news around us.

Maybe you’ve had the same experience:

Baidu Search “How to Learn Micro Services?” In the result page, all the clicks are advertisements, turning down 5 or 6 pages, and there is no satisfactory answer.

You know what technology to learn in search for “micro services”? How to learn?

Keyboard gods tell you that there are several books…

You buy books home, and each one is as thick as a brick. I guess you’ll think, “It’ll take two years to finish reading these books.” In an instant, from “full of confidence” to “just watch and play”.

So how can we learn microservices easily?

The following methods can help you!

It’s easy to learn.

I’ve summed up two main points for you:

1. Find a good video course and follow Daniel’s well-organized knowledge framework.

2. Practice more.

Author: snail climb

Read the original text

This article is the original content of Yunqi Community, which can not be reproduced without permission.

Recommended Today

Hadoop MapReduce Spark Configuration Item

Scope of application The configuration items covered in this article are mainly for Hadoop 2.x and Spark 2.x. MapReduce Official documents https://hadoop.apache.org/doc…Lower left corner: mapred-default.xml Examples of configuration items name value description mapreduce.job.reduce.slowstart.completedmaps 0.05 Resource requests for Reduce Task will not be made until the percentage of Map Task completed reaches that value. mapreduce.output.fileoutputformat.compress false […]