What is high concurrency, how to avoid high concurrency

Before I will address methods highly concurrent mistaken thread or queue can be resolved , because of the high concurrency when there are many users to access, resulting in system data is not correct, data loss phenomenon , so think of a queue to solve, in fact, the way to solve the queue can handle, such as our in auction goods, forwarding microblogging comments or commodities spike, the same amount of time to access is particularly large, the queue to play a special role in this, all requests in the queue, timing in milliseconds unit, orderly conduct, and thus data loss incorrect system data will not happen .

Today, I go through to find information, high concurrency solutions have two kinds, one is using the cache, and the other is to use a static page generation;

There is the optimization of the most basic place we write the code to reduce the unnecessary waste of resources :(

1. Do not frequently new objects, for instance need only exists a class used throughout the application singleton pattern . For String connecting operation using the StringBuilder or StringBuffer.

For utility type of class accessed through the static method.

2. Avoid using the wrong way , such as Exception can launch control method, but you want to keep Exception stacktrace consumption performance, unless necessary, do not use instanceof some conditions are, as far as possible the conditions of use than the ( way of comparison ) way to judge . Use high efficiency in JAVA classes, such as ArrayList Vector better than the performance . )

First caching technology I have not used, I think it should be when a user requests data stored in the cache, the next will detect whether data exists in the cache when requested, to prevent the repeated request to the server, resulting in reduced server performance, resulting in serious server crashes , this is just my own understanding, still need to collect detailed information on the internet;

Use static page generation, I think we should not model, the last time we've seen a lot of pages on the site when the request has changed, such as "http://developer.51cto.com/art/201207/348766.htm " the in fact, it is a server page request address, after conversion to htm, access speed will increase, because the static pages without a server component; here I will explain a lot:

 

First, what is static pages:

Simply put, if we access a link to the corresponding server module will process the request, go to the corresponding jsp interface, and finally generate the data we want to see. Among the disadvantages are obvious: because each server request will be handled, if there are too many high concurrent requests, it will increase the pressure application server, calling out to put the server is down. So how to avoid it? If we save the result of the request for test.do into a html file, then each user to access, so that the application server is not pressure is reduced?

So static pages come from? We can not let each page manually deal with it? Here involves what we want to explain a static page generation program ... What we need is automatically generated static pages, when a user visits, will automatically generate test.html, and then displayed to the user.

Second, let's look at a brief want to know the static page program should have the knowledge points:

1, basic - URL Rewrite

What is the URL Rewrite it? URL rewriting. Use a simple example to illustrate the problem: Enter the URL, but instead you actually are abc.com/test.action, then we can say that the URL is rewritten. Widespread application of this technology, there are many open source tools can achieve this function.

2, basis - Servlet web.xml

If you do not know web.xml in a request and a servlet is how to match together, then search servlet documents. This is not to utter it, there are a lot of people think /xyz/*.do this method can effectively match.

If you do not know how to write a servlet, then please search on how to write a servlet. This is not a joking way, in a variety of integrated tools filled the air today, many people are not going to write a servlet from zero.

Third, the basic scheme introduced

java high concurrency, how to solve, resolve what - I studied Square - inspirational - I studied Square
Which, for some URL Rewriter, you can use the open source tool or charges to achieve, if not particularly complicated url, you can consider implementing in the servlet, then that looks like this:

 

java high concurrency, how to solve, resolve what - I studied Square - inspirational - I studied Square
 
Summary: In fact, we are rarely considered in the development of this problem, are a direct function realization first, when a programmer till 1-2 years, it will feel to achieve light function is not the most important, safety, quality and so is a developer of the most concern. Today I am saying is that high concurrency, my idea is to solve, 1, 2 uses a distributed application design, distributed caching database 3, code optimization

Guess you like

Origin www.cnblogs.com/xujinlin/p/11248455.html