zoukankan      html  css  js  c++  java
  • PostgreSQL的postmaser的fork的学习体会

    可以说,postmaster是PostgreSQL服务器端的总代理了。
    通过它,把客户端的请求转给新生成的postgres 进程。

    postmaster.c 的代码注释中有如下的描述:

    When a request message is received, we now fork() immediately.
    
    The child process performs authentication of the request, and    
    then becomes a backend if successful.
    
    This allows the auth code to be written in a simple single-threaded style 
    (as opposed to the crufty "poor man's multitasking" code that used to be needed).    
    More importantly, it ensures that blockages in non-multithreaded libraries 
    like SSL or PAM cannot cause denial of service to other clients.

    这个fork的方式是,只要有请求进来了,就fork一个进程。
    然后,认证什么的都有这个进程自己来搞定。然后提出请求的客户端和这个postgres进程之间,该干嘛就干嘛。
    每一对 客户端/postgres进程 和其他的 客户端/postgres进程之间互不干扰。

    想想看,这么做确实有它的好处:
    认证部分的代码可以尽量简化,不需要考虑锁定机制什么的。处理效率比较高,也没有排队什么的。
    另外,如果一个postgres进程崩溃了,也不会影响另一个。

  • 相关阅读:
    java UDP传输
    InetAddress与Socket
    TCP和UDP的联系和用途
    网络通讯要素
    什么是网络编程?
    java 合并流(SequenceInputStream)
    最长上升子序列之基础
    《Linux Device Drivers》第十五章 内存映射和DMA——note
    HDU 5092 DP
    NGUI: UIPanel控件
  • 原文地址:https://www.cnblogs.com/gaojian/p/2599235.html
Copyright © 2011-2022 走看看