美文网首页
Prefork 多进程模型

Prefork 多进程模型

作者: 伍只蚊 | 来源:发表于2018-06-16 15:59 被阅读26次

转:

Prefork 就是预先创建好制定数量的进程来接受请求

t json
import struct
import socket


def handle_conn(conn, addr, handlers):
    print addr, "comes"
    while True:
        length_prefix = conn.recv(4)
        if not length_prefix:
            print addr, "bye"
            conn.close()
            break  # 关闭连接,继续处理下一个连接
        length, = struct.unpack("I", length_prefix)
        body = conn.recv(length)
        request = json.loads(body)
        in_ = request['in']
        params = request['params']
        print in_, params
        handler = handlers[in_]
        handler(conn, params)


def loop(sock, handlers):
    while True:
        conn, addr = sock.accept()
        handle_conn(conn, addr, handlers)


def ping(conn, params):
    send_result(conn, "pong", params)


def send_result(conn, out, result):
    response = json.dumps({"out": out, "result": result})
    length_prefix = struct.pack("I", len(response))
    conn.send(length_prefix)
    conn.sendall(response)


def prefork(n):
    for i in range(n):
        pid = os.fork()
        if pid < 0:  # fo...

https://juejin.im
掘金 — 一个帮助开发者成长的社区

相关文章

  • Prefork 多进程模型

    转: Prefork 就是预先创建好制定数量的进程来接受请求

  • nginx I/O模型

    HTTPD MPM prefork : 进程模型,两级结构,主进程master负责生成子进程,每个子进程负责响应一...

  • I/O模型

    我们这里先介绍 一下相关的知识点 1.Httpd MPM  httpd MPM: prefork:进程模型,两...

  • apache配置与优化

    Apache 的三种模式 prefork 多进程模式 一个主进程,负责生成多个子进程,也称工作进程,进程之间独立,...

  • Linux_216_apache的工作模式

    apache的工作模式(多进程工作模式) 使用httpd -V,Server MPM: prefork检查...

  • apache 性能调优

    一:apache的工模式有三种: prefork、woker 与event. preforkMPM 使用多个子进程...

  • HTTP 之 MPM工作模式

    .MPM:multi-processing module多路处理模块,支持三种I/O模型:prefork,work...

  • apache工作模式

    apache有三种工作模式: 1.prefork: 是一种进程、与派生的工作模式,用的是进程去处理请求,所以比较容...

  • Apache prefork、worker的工作原理

    一、prefork 的工作原理 如果不用“--with-mpm“显式指定某种 MPM, prefork 就是 Un...

  • 2.Linux内核学习之Linux进程调度初探(1)进程调度的策

    1 进程状态模型 在操作系统中,进程的状态模型一般可以用进程五状态模型来概括,其他模型只是在五状态模型上的增删。 ...

网友评论

      本文标题:Prefork 多进程模型

      本文链接:https://www.haomeiwen.com/subject/fzsbeftx.html