Before I’ll high concurrency solutions is mistaken for thread or queue can be solved, because when high concurrency is a lot of users in access, lead to the phenomenon of system data is not correct, the loss of data, so think of solve with the queue, queue actually solve way can also processing, such as we in the auction goods, forward comment on weibo or kill goods, etc., When traffic is particularly high at the same time, the queue plays a special role in this, putting all requests into the queue, in milliseconds, in order, from There will be no data loss and the system data is incorrect
Situation.
I did some research today
There are two solutions to high concurrency, one is to use caching, the other is to generate static pages; There is also from the most basic place to optimize our code to reduce unnecessary waste of resources 🙁
1. Avoid frequent new objects and use the singleton pattern for classes that require only one instance in the entire application. For String concatenation, use StringBuffer or StringBuilder. Classes of utility type are accessed through static methods.
2. Avoid using wrong methods. For example, Exception can control method rollout, but Exception should retain stackTrace consumption performance. Using efficient JAVA classes such as ArrayList performs better than Vector.
First of all, I haven’t used the cache technology, I think I should is when the user requests the data stored in the cache, the next request when testing the cache data does exist, prevent multiple requests the server, results in the decrease of server performance, serious cause server crash, it is just my own understanding, detailed information is needed on the Internet collecting;
With generating static pages I think you should be out of mode, we’ve seen a lot of sites where the back of the page has changed when requested, Such as “[url] http://developer.51cto.com/art/201207/348766.htm [/ url]” the page request is actually a server address, after conversion to HTM, access speed will increase, because the static page without a server component; Here I would like to introduce more:
First, what is page static:
Simply put, if we visit a link, the server’s corresponding module will process the request, go to the corresponding JSP interface, and finally generate the data we want to see. The downside is obvious: because the server processes every request, if there are too many high-concurrency requests, the application server will be stressed and the server will be brought down. So how to avoid it? Wouldn’t the application server be less stressed if we saved the result of the test.do request to an HTML file that the user accessed each time?
So where do static pages come from? We can’t do every page manually, can we? This is where we get to, static page generation… What we need is to generate static pages automatically. When the user visits, test.html will be generated automatically and displayed to the user.
Two, the following is a brief introduction to the knowledge points we should master in order to master the page static scheme:
1, basic – URL Rewrite
What is URL Rewrite? The URL rewrite. To illustrate, a simple example: if you type in the URL, but you actually visit abc.com/test.action, you can say that the URL has been rewritten. This technique is widely used, and there are many open source tools that can do this.
2. Basics – Servlet web.xml
If you don’t know how a request and a servlet match up in web.xml, search the servlet documentation. This is not nonsense. There are many people who think that /xyz/*.do matches work.
If you don’t know how to write a servlet, do a search on how to write a servlet. This is not a joke, in all kinds of integrated tools flying
Today, most people wouldn’t write a servlet from scratch.
Iii. Basic scheme introduction
The URL Rewriter part can be implemented using paid or open source tools. If THE URL is not particularly complex, it can be implemented in servlets, which looks like the following:
Summary: in fact, we rarely consider this problem in the development, are directly the first function implementation, when a programmer in the work to 1 or 2 years, will feel that the light implementation function is not the most important, safety performance, quality and so on is a developer the most concerned. Today I am talking about high concurrency, and my solution is: 1, using distributed application design, 2, distributed cache database, 3, code optimization