openrestry

OpenResty Best Practices-Introduction

Posted by

Introduction

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 rubbing together many well-designed Nginx modules, OpenResty effectively transforms the Nginx server into a powerful Web application server. Based on it, developers can use Lua programming language to script Nginx core and existing Nginx C modules and build extremely high-performance Web applications that can handle more than 10,000 concurrent requests.

OpenResty is dedicated to fully running your server-side applications on Nginx servers, making full use of Nginx’s event model for non-blocking I/O communications. Not only is the network communication with HTTP clients non-blocking, but also with MySQL, PostgreSQL, Memcached and Redis, and many other remote backends.

Because the maintainer of the OpenResty package is also the author of many of the Nginx modules packaged therein, OpenResty ensures that all the components contained can work reliably together.

OpenResty was originally a Yahoo China company project, which started in October 2007. OpenResty was born with the rise of OpenAPI to meet the needs of various Web services. With the support of company leaders, the earliest OpenResty implementations were open source from the beginning. Originally aimed at serving developers outside the company, like other OpenAPIs, Yahoo’s search products in China were increasingly offered in-house services. This is the first generation of OpenResty. The idea at that time was to provide an abstract set of Web services to enable users to use these web services to construct new web services that meet their specific business needs. Therefore, some “meta web services” meanings, including data models, queries and security policies, can be expressed and configured through this meta web service. At the same time, this web service also intends to maintain the REST style. Corresponding to this concept is pure AJAX web applications, that is, web applications are almost written using client JavaScript, and the web services make web applications “live”. Users download static files such as. HTML,. js, CSS,. JPG to a web browser, then JS starts to run, cross-domain requests from Yahoo to provide customized web services by webmaster, and then the application can run. However, with the development of the company, the number of users outside the company is still small, so the focus of the application is to provide web services for other teams within the company, such as Yahoo China’s omnipotent search products, and some of its peripheral products. Since then, the focus of development has been on performance optimization. After joining the quantum team of Taobao Data Department, Zhang Yichun decided to redesign and rewrite OpenResty completely, focusing on supporting web products such as quantum statistics, so Quantum Statistics 3.0 started almost entirely as a web service-driven pure AJAX application.

This is the second generation of OpenResty, commonly known as ngx_openresty, to distinguish it from the first generation of OpenResty based on Perl and Haskell. Zhang Yichun and his colleague Wang Xiaozhe designed the second generation of OpenResty. Under the proposal of Wang Xiaozhe, the development is based on Nginx and Lua.

Why take the name OpenResty? OpenResty was first adapted to the trend of OpenAPI, so Open came from the meaning of “open” and Resty is the meaning of REST style. Later, any form of web service or traditional web application can also be implemented based on ngx_openresty.

That is to say, Nginx is no longer a simple static web server, nor a simple reverse proxy. The second generation of openresty is dedicated to expanding nginx into a full-featured Web application server through a series of nginx modules.

Ngx_openresty is a user-driven project. Later, many domestic users participated. From the distribution of openresty.org clicks, domestic and foreign clicks are basically the same.

Ngx_openresty currently has two main application objectives:

  1. Universal purpose web application server. Under this goal, existing web application technologies are more or less similar to OpenResty, such as Nodejs, PHP and so on. The performance of ngx_openresty (including memory usage and CPU efficiency) is one of the biggest selling points.
  2. Nginx script extension programming is used to build a flexible Web application gateway and Web application firewall. Some are similar to NetScaler. Its advantage lies in the great flexibility brought about by Lua programming.

Ngx_openresty was the product of the company’s actual business needs from the beginning. In the past few years, most of the development work has been driven by the actual business needs of many companies and individuals at home and abroad. This model works very well in practice to ensure that what we do is what we need most urgently. In this process, two major application directions of ngx_openresty are gradually formed, which are the two directions mentioned above. Our users helped us identify these two directions. In fact, this is not the same as the direction of the first generation of OpenResty but is becoming more bottom-level and more general-purpose.

The core of the open source spirit is sharing rather than pursuing popularity. After all, open source is not entertainment, nor fashion. If our open source project is used by more and more people, just a “happy accident”, we will be happy, but this is not what we really pursue.

Open source is only the first step in the life cycle of open source projects. Many domestic open source projects stop at open source, and do not follow up with long-term time and effort to respond to users’needs and feedback, but inevitably die. This phenomenon is also common in many open source projects abroad.

There are many successful open source projects abroad, perhaps related to the mental state of programmers in many developed countries. For example, some foreign hackers I know are very simple-minded and enthusiastic. They have very little mental restraint and do things in a very informal way. Some people will spare no effort to devote themselves to open source projects, even if they have no job for a long time and live solely on mortgages and donations. However, many of the domestic programmers I have come into contact with generally have a heavy mental burden and great economic pressure. Naturally, it is difficult to have the idea of “playing open source”.

However, there are also some programmers in China who have the quality of excellent hackers from abroad, and they are closely linked with hackers from all over the world through the network, so we can fully expect them to have exciting output in the future. In the age of the Internet, it may be more and more inappropriate to discuss such issues according to the division of national boundaries.