The lamp architecture evolves to LAMPGC and then to LNMLGC (LINUX+NGINX+MYSQL+LUA+GEARMAN+C)

Source: Internet
Author: User
Tags lua

Lamp is a public structure, linux+apache+mysql+php.

In the architecture of our system, we have made further progress, linux+apahce+mysql+php+gearman+c

PHP as a page display

Core business logic is implemented by C language, and PHP calls C task through Gearman middleware


Because Apache is not very force-efficient in high concurrency, we further evolve in scenarios where high concurrency is required, linux+nginx+mysql+php+lua+gearman+c

The page section is displayed by NGINX+FASTCGI+PHP-FPM.

High concurrent business calls are implemented by Nginx+lua+gearman+c


Here, we highlight how Nginx calls Gearman middleware.

First look at the situation of apache+php call Gearman, synchronous call a Gearman task, if this task to 3S clock, then the current Apache httpd process will be blocked, it can not serve other clients


Nginx in high concurrent asynchronous invocation of the sex can be strong, this earth people know

Lua can also implement concurrent asynchronous calls

Let's take a look at the implementation of Nginx+lua call Gearman:

Nginx is also a worker,worker process to invoke the Gearman task through the LUA coprocessor, even if the task is 3S clock, in this 3 S-clock The worker process can serve other clients, This relies on the benefits of Nginx's Epoll event-triggering non-blocking calls and the LUA asynchronous invocation, which enables high-concurrency business calls.


The following is a Lua-nginx-module installation and simple configuration process:

1. Required source files shell> lsdrwxr-xr-x 6 4096 03:14 luajit-2.0.3drwxrwxr-x root root 4096 June 1 2014 Lua-nginx-module-0.9.8drwxr-xr-x 9 1001 1001 4096 Feb 03:14 nginx-1.7.2drwxrwxr-x 9 root root 4096 Sep 26 02:4 3 Ngx_devel_kit-0.2.19drwxr-xr-x 8 1169 1169 4096 Feb 03:17 pcre-8.212, installation luajithttp://luajit.org/download/luajit-2. 0.3.tar.gzshell> CD luajit-2.0.3shell> makeshell> make install because the default path is installed, Luajit corresponding Lib,include is in/usr/ Local directory. 3. Compiling Nginxhttps://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.8https://codeload.github.com/simpl /ngx_devel_kit/tar.gz/v0.2.19shell>./configure--prefix=/usr/local/nginx--add-module=. /ngx_devel_kit-0.2.19--add-module=. /lua-nginx-module-0.9.8--with-pcre=. /pcre-8.214, start nginxshell> cd/usr/local/nginx/sbinshell>./nginx./nginx:error while loading shared libraries: Libluajit-5.1.so.2:cannot open Shared object file:no such file or directory hints that Luajit library files could not be found shell> echo "/usr/local/lib">/etc/ld.so.conf.d/usr_local_lib.confshell> ldconfigshell>./nginx Success 5, Nginx application Add the following configuration to the/usr/local/nginx/            Conf/nginx.conf: Location/lua {set $test "Hello, World";                Content_by_lua ' Ngx.header.content_type = "Text/plain";            Ngx.say (ngx.var.test);        '; }shell>./nginx-s Reload Browse drops Q: Http://172.16.18.114/lua display: Hello, world. 6, install Lua-resty-gearman module Https://github.com/zhhchen/lua-resty-gearman/tree/master/lib/resty7, Nginx calls Gearman in the nginx.conf HTTP segment by LUA script to add: Lua_package_path "/usr/local/lua-resty-gearman/lib/?". LUA;; ";                Added under Server: location/test {content_by_lua ' local Gearman = require "Gearman" Local GM = Gearman:new () gm:set_timeout (+)--1 sec ngx.header.content_type = "T                    Ext/plain "Local OK, err = Gm:connect (" 172.16.18.162 ", 4730) if not OK then Ngx.say ("Failed to ConneCT: ", err) return end OK, err = gm:submit_job (" reverse "," abcdef ")                --SUBMIT_JOB,SUBMIT_JOB_BG,SUBMIT_JOB_HIGH,SUBMIT_JOB_HIGH_BG,SUBMIT_JOB_LOW,SUBMIT_JOB_LOW_BG is supported --Submit_job (function_name, workload[, unique]) if not OK then Ngx.say ("FA Iled to submit job: ", err) return else Ngx.say (ok) en D--put it into the connection pool of size,--with 0 idle timeout loca  L OK, err = gm:set_keepalive (0, +) if not OK then Ngx.say ("Failed to set KeepAlive:",                ERR) return end--or just close the connection right away:                --local OK, err = Gm:close ()--If not OK and--Ngx.say ("Failed to close:", err) --RETurn-end '; } Browse drops Q: http://172.16.18.114/test display: FEDCBA

Related Article

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.