Hi,

Luasocket is not compliant with haproxy i/o and blocks the process waiting for the socket response.

You should use core.tcp() which provide the same interface that luasocket and it is compliant wit haproxy i/o.

Thierry


Le 25 octobre 2017 5:37:17 AM aogooc xu <[email protected]> a écrit :

Use luasocket(HttpUtil) in service code example:

    local method = service.get_method(applet)

    local url

    do

        url = applet.path

        if applet.qs ~= '' then

            url = url .. "?" .. applet.qs

        end

    end

    local upstream = "http://"; .. host .. url


    local httputil = util.HttpUtil()

    local resStr, res, code, t, response_headers

    local request_headers do

        request_headers = {}

        local h = applet.headers

        for k, v in pairs(h) do

            local header_string = ''

            for idx, header_v in pairs(v) do

                if idx > 0 then

                    header_string = header_string .. ", " .. header_v

                else

                    header_string = header_v

                end

            end

            request_headers[k] = header_string

        end

        request_headers['accept-encoding'] = nil

    end


    if method == "GET" then

        local query_string do

        if string.find(upstream, '?', 1, true) == nil then

            _, query_string = util.split(upstream, "?")

        end

    end

        res, code, response_headers, t = httputil.httpGet(upstream,
request_headers, query_string)


    else

        local body do

        if request_headers["content-length"] ~= '0' then

            body = service.get_body(applet)

        else

            body = ''

        end

    end


        res, code, response_headers, t = httputil.httpBase(method,
upstream, request_headers, body)

    end


    if res == 1 then

        resStr = t

    else

        resStr = res or ''

    end


    if response_headers then

        for k, v in pairs(response_headers) do

            -- refactor: set-cookie value is table

            if k == "set-cookie" then

                for _, val in pairs(v) do

                    applet:add_header(k, val)

                end

            else

                applet:add_header(k, v)

            end

        end

    end


    applet:set_status(code)

    applet:start_response()

    applet:send(resStr)



In backend use this config, will lead to other requests to wait.

Use a new socket effect ? maybe I should use core.tcp ?


2017-10-24 18:36 GMT+08:00 Moemen MHEDHBI <[email protected]>:

Hi,

What do you mean exactly by blocking,  blocked from doing what ?

The use-service will make HAProxy use the LUA script instead of a
backend server when "proxying" the request.

++

On 24/10/2017 10:38, aogooc xu wrote:
> hello,
>
> I would like to achieve a register in the register_service mini http
> proxy, dynamic processing request
>
> * problem
>
> Use luasocket in lua code,will cause blocking ?
>
> Test 10 concurrent requests,example
>
> ab -c 10  -n 1000  http://127.0.0.1/test/
>
> It will block and wait for all requests to be completed, I am confused。
>
>
> haproxy cfg exmaple:
>
> http-request use-service lua.haproxy-proxy
>
>
>
>
>

--
Moemen MHEDHBI



Reply via email to