最近聽說lua在高並發上優勢非常明顯,只知道http://blogcn.com/和http://www.tisiwi.com/兩個站是採用lua支持的,還有此類網站嗎?


淘寶的量子統計(http://lz.taobao.com)就是使用lua開發的 使用nginx+ luajit ,目前大家可以使用ngx_lua的模塊進行網站的開發,跟普通的lamp相比,完全非阻塞是一個亮點,完全不會阻塞在mysql,memc上面。感覺lua的前景還是不錯的
有一個網站是用OpenResty+LUA,而寫的網站,用的WEB框架是LOR,網址 OpenResty China 而在國外也有一些用Lua寫的網站,使用的框架有的可能是用Lapis寫的, 例如: Streak Club


EventServer基於lua和libevent的完全非同步、高性能的web框架。既可以作為遊戲服務,也可以做web服務,支持websocket和https。

關鍵是可以ffi使用c/c++庫,比如libcurl和iconv,也可以調用第三方lua庫,比如smtp、redis、luasql等,採用委託線程執行的方式實現對io阻塞操作的非同步調用,方便簡單。

lua-web網站?

www.lua-web.com

框架代碼開源下載?

gitee.com圖標EventServer/blog?

gitee.com圖標

簡單用法如下:

--首頁
local function http_html_index(req)
print(http_html_index)
local header = evhttp_get_input_headers(req)
local ip = evhttp_get_remote_host(req)
local id = evhttp_hash(ip)

local parameter = evhttp_parse_query(req)
local page = tonumber(parameter.page and parameter.page or 1)
page = (page&<=0) and 1 or page local tab = parameter.tab local and_str = tab and and a.category=..tab.. or local hots = load_hot_docs() local bookmarks = load_bookmarks() local sql = [[SELECT count(1) as cnt FROM blogs.documents as a where a.post_status=0]]..and_str..[[ ;]] local ret,rows=ExecuteSQL(THREADID_SQL+math.mod(id,10), sql,true) if not ret then print(http_html_index ************************) return end local pages=math.floor(tonumber(rows[1].cnt)+9/10) local offset = (page-1)*10 local sql = [[SELECT a.`id`, b.nickname as post_author, a.`post_date`, a.`post_title`, a.`post_status`, a.`category`, a.`post_desc`, a.`read_count`, a.`comment_count` FROM `blogs`.`documents` as a,`blogs`.`accounts` as b where a.post_status=0 and a.post_author=b.userid]]..and_str..[[ order by a.post_date desc limit ]]..offset..[[,10;]] local ret,rows=ExecuteSQLBatch(THREADID_SQL+math.mod(id,10), {sql},true) if not ret then print(http_html_index ************************) return end local tabs = { {name=GetUtf8ByGBK(全部), url=index.html }, {name=GetUtf8ByGBK(EventServer), url=index.html?tab=.. GetUtf8ByGBK(EventServer) }, {name=GetUtf8ByGBK(Python), url=index.html?tab=Python }, {name=GetUtf8ByGBK(AI), url=index.html?tab=AI }, {name=GetUtf8ByGBK(Game), url=index.html?tab=.. GetUtf8ByGBK(Game) }, {name=GetUtf8ByGBK(寫文章), url=edit.html}} local context = {title=convert2utf8(首頁), page=page,pages=pages,count=QUERY_COUNT,tabs=tabs,bookmarks=bookmarks,hots=hots,tab=tab and tab or GetUtf8ByGBK(全部),articles=rows} local template = require "html.template" local res = template.render(SERVER_DIRECTORY.."/asset/html/index.html", context, "no-cache" ) HttpRespone(req, function() evhttp_add_header(req, Content-Type, "text/html") evhttp_send_reply(req,200,ok, res) end) print(********************Cookie, json.encode(header), header.cookie) end


這也是用 lua 寫的哦~ lua 中國開源社區 本身就是 lua 的社區,用的是 nana 框架


lua是一種寄生語言,因此,所謂lua開發的網站,其實核心並不會是lua,一般底層核心都是C語言寫的某些庫或者組件、模塊,比如nginx、libev、libuv,或者直接用C寫底層。所以,lua高並發的優勢其實主要靠底層C語言的庫的支持,lua其實主要是做頻繁變化的業務邏輯開發。所謂lua高並發的優勢主要是1、lua支持協程 2、lua非常輕量,new一個實例消耗的資源很小。因此,在解釋型腳本語言來說。相比node.js、Python、ruby等等,lua是有優勢的。但是lua也有解釋型語言共同的弱點,比如:沒有編譯期檢查因此不適合大型項目。lua的第三方支持也比Python弱。lua開發的網站應該算比較小眾。


由淘寶的工程師清無(王曉哲)和春來(章亦春)所開發的nginx_lua_module可以將Lua語言嵌入到Nginx配置中,從而利用Lua極大增強了Nginx本身的編程能力,甚至可以不用配合其它腳本語言(如PHP或Python等),只靠Nginx本身就可以實現複雜業務的處理。而春來所開發的ngx_openresty更是通過集成LuaJIT等組件,將Nginx本身變成了一個完全的應用開發平臺。目前淘寶數據平臺與產品部量子統計的產品都是基於ngx_openresty所開發。來源:CodingLabs - Nginx模塊開發入門
這是用lua開發的網站。

木棉樹下.同城大學生交友社區

使用的是如下框架:daogangtang/bamboo · GitHub
目前我們並未在lua平臺上開發更多項目,外界使用 lua 構建的網站估計非常非常少


推薦閱讀:
相關文章