preface

Welcome to our GitHub repository Star: github.com/bin39232820… The best time to plant a tree was ten years ago, followed by now. I know many people don’t play QQ anymore, but for a moment of nostalgia, welcome to join the six-vein Shenjian Java rookie learning group, group chat number: 549684836 encourage everyone to write blog on the road of technology

omg

What about this one? Basically a line of the company with a plan, our company to reach this level, of course, but also useful to this part of the solution, and then I saw this system, is to learn, then I intend to make a record, not necessarily said he followed the dry step by step, but the thought I must have to learn to and youdao without art, the art fair, Art without tao, stop in art. So we’re going to learn one thing, and I think it’s just a matter of seeing the road before we actually practice it. My side is also a general study of the overall idea, record, all kinds of details we have to decompose a technical point to achieve. It’s just a simple learning record, and there are several important points to this plan

  • Redis high availability and high performance cache architecture
  • Openrestry High-performance Web server

Product detail page multi – level caching practice

Product detail page architecture requirements -> high availability, -> high performance, -> high concurrency; Generally speaking, the industry is divided into a mainstream solution

  • Detail page scheme for smes
  • Head big company’s scheme

Detail page scheme for smes

Many small and medium-sized e-commerce companies may not have a visit to the product details page in a minute, in this case, there is no concurrent design, a Tomcat can be done.

What about small and medium sized companies? Although the company is not big, there are hundreds of thousands of days to live. And then a couple of million users, companies that are a little bit bigger, their product details might take a global static page that looks something like this

  • What does that mean? What we do is we make the product details page a static page directly, and then we put all the data into Nginx statically, every time the data changes, we render the data through a Java service, and then push the static page to the Nginx server. (I haven’t done this either, I thought to see if I can put the generated static page in OSS, and then configure a regular URL to access the static page directly through nginx.)
    • The disadvantage of this scheme is that if there are many items, the rendering time will be too long to achieve real-time effect
    • Can only handle some static things, if there is a lot of dynamic data, such as inventory, you can’t say every time to render and then push to the Nginx server, isn’t that slower?

The core idea of a large company’s product detail page

How can I put it? This diagram above can explain his core idea, here small 60 60 steps to explain to you

  • The first step is the user through a home page, I entered the home page, and then I saw a product, this time I can only see part of the information of the product, right, that needs to see the details, so I have to click in, at this time I requested a URL, here small 66 will casually cite an example, for example: www.hqjy.com/goods/10086;
  • Step two, what about this URL? It will go through our LB LVS, then to our Nginx cluster, and then nginx will find the static template of the product detail page, and then there is a lua script that can go to nginx to view the dynamic data of the product id 10086. If the product 10086 does not have nginx cache, Lua can request Redis. If the product 10086 does not have NGINx cache, Lua can directly call the product’s cache service (Tomcat), and then the product service will check mysql ES and other db to find the data and then cache it to Redis. And then it’s cached in nginx, so it’s a closed loop,
  • Advantages do not fully update, and do n level cache, can do more high availability, high performance, high concurrency

The structure of the Redis

In fact, where is the key to the success of the above product details page scheme? Yes is our Redis architecture, your Redis QPS can reach hundreds of thousands of per second, and then can do real-time data backup, and ensure 99.99 percent of the service available.

Redis, the cloud service used by our company, usually needs to be built by ourselves. How to consider its persistence plan and the true meaning of persistence

In fact, this is the knowledge related to Redis, but in high concurrency scenarios redis is necessary, for the use of Redis high availability read/write separation architecture, not here, but redis is the cornerstone of high concurrency

Several algorithms for distributed data storage

  • Simplest Hash algorithm

  • Consistency of the hash

  • hash slot

What is Openresty?

What is OpenResty?

OpenResty® is a Web platform based on NGINX and LuaJIT.

OpenResty (also known as NGx_OpenResty) is a full-featured Web application server. It packages the standard Nginx core, many commonly used third-party modules, and most of their dependencies.

By incorporating many well-designed Nginx modules, OpenResty effectively transforms the Nginx server into a powerful Web application server that allows developers to script the Nginx core and various existing Nginx C modules using the Lua programming language. Build extremely high performance Web applications that can handle more than 10,000 concurrent requests.

With Nginx’s event-driven model and non-blocking IO, high-performance Web applications can be implemented. Furthermore, OpenResty provides a large number of components such as Mysql, Redis, Memcached, and so on, making it much easier to develop Web applications on Nginx. Currently, JINGdong, Taobao and Qunar are all using Nginx+Lua architecture.

Download and install Openresty

Xiao Liuliu himself installed it through the official website, so I give you an official website address -Openresty. In fact, I think it was written by a Chinese person, so the document has good support for Chinese, haha.

Download the source package

My side is based on centos installation

  • Step one, create a directory like me
mkdir /data/openresty 
Copy the code
  • Step 2 Download the package and decompress it
Wget https://openresty.org/download/openresty-1.15.8.2.tar.gz tar - ZXVF openresty - 1.15.8.2. Tar. GzCopy the code
  • The third step is to install the libraries you must have perl 5.6.1+, libpcre, libssl installed on your computer. For Linux, you need to be sure to use the LDconfig command to find them in your system environment path.
yum install pcre-devel openssl-devel gcc curl
Copy the code
  • The fourth step
 ./configure 

Copy the code
  • Step 5 make
make
Copy the code
  • Step 6
sudo make install
Copy the code

When you have completed the above steps, you should now have OpenRestry installed,

Once that’s done, you’ll go to /usr/local/openresty and that’s the whole project

Hello Word

Create several directories

mkdir ~/work
cd ~/work
mkdir logs/ conf/
Copy the code

conf/nginx.conf

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}
http {
    server {
        listen 8080;
        location / {
            default_type text/html;
            content_by_lua_block {
                ngx.say("<p>hello, world</p>")}}}}Copy the code

Assuming you have OpenResty installed to /usr/local/openresty (which is the default), we will provide the nginx executable for the OpenResty installation: PATH in the environment

PATH=/usr/local/openresty/nginx/sbin:$PATH
export PATH
Copy the code

We then start the nginx server with the following configuration file:

nginx -p `pwd`/ -c conf/nginx.conf
Copy the code

Then we shut down the server

At the end

Openresty=nginx+ Lua: This is an introduction to the Redis cache architecture, and a very simple introduction to Openresty. Part of the article content is small 66 to B station search title study summary

Daily for praise

Ok, everybody, that’s all for this article, you can see people here, they are real fans.

Creation is not easy, your support and recognition, is the biggest motivation for my creation, we will see in the next article

Six pulse excalibur | article “original” if there are any errors in this blog, please give criticisms, be obliged!