zoukankan      html  css  js  c++  java
  • lua-resty-gearman模块

    粘贴一段百度对gearman的解释:

    Gearman是一个用来把工作委派给其他机器、分布式的调用更适合做某项工作的机器、并发的做某项工作在多个调用间做负载均衡、或用来在调用其它语言的函数的系统。

    lua-resty-gearman模块用于在lua中调用gearman

    github地址   https://github.com/zhhchen/lua-resty-gearman

    调用的代码样例:

    lua_package_path "/path/to/lua-resty-gearman/lib/?.lua;;";
    
    server {
        location /test {
            content_by_lua '
                local gearman = require "resty.gearman"
                local gm = gearman:new()
    
                gm:set_timeout(1000) -- 1 sec
    
                local ok, err = gm:connect("127.0.0.1", 4730)
                if not ok then
                    ngx.say("failed to connect: ", err)
                    return
                end
    
                ok, err = gm:submit_job("wc", "11111
    22222
    33333")  
                -- submit_job,submit_job_bg,submit_job_high,submit_job_high_bg,submit_job_low,submit_job_low_bg are supported
                -- submit_job(function_name, workload[, unique])
                
                if not ok then
                    ngx.say("failed to submit job: ", err)
                    return
                else
                    ngx.say(ok)                
                end
    
                -- put it into the connection pool of size 100,
                -- with 0 idle timeout
                local ok, err = gm:set_keepalive(0, 100)
                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 then
                --     ngx.say("failed to close: ", err)
                --     return
                -- end
            ';
        }
    }

    gearman提交工作时有多种方式:

    submit_job为普通的工作任务,client得到状态更新及通知任务已经完成的响应;

    submit_job_bg为异步的工作任务,client不关心任务的完成情况;

    submit_job_high为高优先级的工作任务;

    submit_job_high_bg为高优先级的异步任务;

    submit_job_low为低优先级的工作任务;

    submit_job_low_bg为低优先级的异步任务。

  • 相关阅读:
    MySQL(一)
    HTML基础
    python函数基础
    常用的模块
    面向对象进阶
    定制自己的数据类型
    Shell篇之AWK
    MATLAB如何实现傅里叶变换FFT?有何物理意义?
    傅里叶分析
    2018年度关键词
  • 原文地址:https://www.cnblogs.com/wangzhisdu/p/7766376.html
Copyright © 2011-2022 走看看