Java Cluster optimization--nginx+tomcat cluster configuration-theory

Source: Internet
Author: User

We understand that the growth of data is a problem that we inevitably face, because in the increasingly changing technology, the way we collect data and the upgrading of storage and processing technology, forcing us to face this problem, and in the increasingly hot data mining today, we also need to pay attention to such issues, change is inevitable!

We have thought, in the extreme optimization of the situation, a common server, can be mined out infinite potential, and I did do this, with a 20,000-dollar device, carrying the concurrent of more than 10,000 people, but with the technology derivative, we need more flexibility to handle the application, we need more timely response speed, We need to analyze and process the data in real time! At this time, we must contact a word, cluster, today, we will build a simple tomcat cluster, for everyone to uncover the tip of the iceberg.

function

In fact, the role of Nginx is very simple, is to do proxy server, then what is the proxy server? You see:




We see, the picture in the middle of the yellow machine is the proxy server, in fact, the proxy server is the Internet access to the company's server address requests, all through a machine for forwarding, by this machine to do load balancing! This technology, in fact, early on, we use the Internet agent, is such a practice, of course, the nginx here is not only the forwarding agent, but also to provide a long-term stable service to do a lot of efforts.


principlemulti-process Model


In Nginx, this multi-process structure before just in theory heard, now know to see the real implementation, then, what is the difference between this and multithreading, we use a table on the internet to explain:



contrast dimension

multi-process

multithreading

summary

data sharing , synchronization

data sharing complex, need to use IPC; data is separate, synchronization simple

because sharing process data, data sharing is simple, but also because of this cause synchronization complex

Each has an advantage

memory, CPU

memory-intensive, switching complexity, low CPU utilization

Low memory consumption, simple switching, high CPU utilization

threading advantage

create Destroy , toggle

Create destroy, switch complex, slow speed

Create destroy, switch simple, fast speed

threading advantage

programming, Debug

simple programming, simple debugging

programming complex, debugging complex

process dominant

reliability

process does not interact with each other

A thread hanging off will cause the whole process to hang up

process dominant

Distributed

Adaptable to multi-core, multi-machine distributed; if one machine is not enough, it is easier to extend it to multiple machines.

Adaptable to multi-core distributed

Process-dominated

It's a question about which is better, but it's not the rock that's going to annoy us, we usually choose according to the situation, but here we talk more, we have time to discuss this direction. In Ngnix, the woker process is mainly used to deal with network events, each woker process is peer and independent, they are equally competitive from the client's request, a request can only be processed in a woker process, the number of Woker process is generally set to the number of machine CPU cores.



non-blocking structure

A practical example of life to help you understand how blocking is going

Blocking
A blocking call means that the current thread is suspended until the call results are returned (the thread goes into a non-executable state where the CPU does not allocate a time slice to the thread, that is, the thread pauses). Functions are returned only after the result is obtained.
Examples of eating:

For example, when you order a meal at one of your restaurants, you don't know when the dish is ready, and you can't do anything else, just wait. You can take a break (sleep) and wait for the waiter to wake up (the dish is ready).


Non-blocking
The concept of non-blocking and blocking corresponds to a function that does not block the current thread and returns immediately until the result is not immediately available.

Examples of eating:

For example, to your restaurant ordering, but you are called takeout, you do not know when the dish is ready, but you can do other things, you can see at intervals every time there is no phone, the dish will call you to eat (the dish has been done)

General blocking structure, will waste a part of the time, non-blocking structure will be the most efficient to complete this part of the work, we look at the time of the process diagram:


Summary:

Nginx is a very good reverse proxy implementation tool, it is very clear, the size of only less than 2m, but to us so simple, practical, efficient to provide quality service, this design concept is what we need to learn, in the future product architecture design, we also want to hold such a principle, is small and beautiful, The principle of fine and excellent, the software to create art!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Cluster optimization--nginx+tomcat cluster configuration-theory

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.