All Projects → muayyad-alsadi → python-PooledProcessMixIn

muayyad-alsadi / python-PooledProcessMixIn

Licence: other
Fast Concurrent Pool of preforked-processes and threads MixIn for python's socket server

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to python-PooledProcessMixIn

HiFramework.Unity
Based on component to manage project's core logic and module used in unity3d
Stars: ✭ 22 (-29.03%)
Mutual labels:  thread, pool
fastthreadpool
An efficient and lightweight thread pool
Stars: ✭ 27 (-12.9%)
Mutual labels:  thread, pool
Oeasypool
c++11 thread pool
Stars: ✭ 18 (-41.94%)
Mutual labels:  thread, pool
Workly
A really simple way to move a function or class to a web worker. 🏋️‍♀️→ 😄
Stars: ✭ 1,848 (+5861.29%)
Mutual labels:  thread
Java Concurrent Programming
📓 《实战Java 高并发程序设计》笔记和源码整理
Stars: ✭ 162 (+422.58%)
Mutual labels:  thread
Libchef
🍀 c++ standalone header-only basic library. || c++头文件实现无第三方依赖基础库
Stars: ✭ 178 (+474.19%)
Mutual labels:  thread
Wasm Worker
Move a WebAssembly module into its own thread
Stars: ✭ 215 (+593.55%)
Mutual labels:  thread
Gl vk threaded cadscene
OpenGL and Vulkan comparison on rendering a CAD scene using various techniques
Stars: ✭ 143 (+361.29%)
Mutual labels:  thread
Gear Lib
Gear-Lib, C library for IOT Embedded Multimedia and Network
Stars: ✭ 2,381 (+7580.65%)
Mutual labels:  thread
Java Concurrency Examples
Java Concurrency/Multithreading Tutorial with Examples for Dummies
Stars: ✭ 173 (+458.06%)
Mutual labels:  thread
Sobjectizer
An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.
Stars: ✭ 172 (+454.84%)
Mutual labels:  thread
Lightio
LightIO is a userland implemented green thread library for ruby
Stars: ✭ 165 (+432.26%)
Mutual labels:  thread
Q
A platform-independent promise library for C++, implementing asynchronous continuations.
Stars: ✭ 179 (+477.42%)
Mutual labels:  thread
Sc
Common libraries and data structures for C.
Stars: ✭ 161 (+419.35%)
Mutual labels:  thread
Preact Worker Demo
Demo of preact rendering an entire app in a Web Worker.
Stars: ✭ 204 (+558.06%)
Mutual labels:  thread
Func timeout
Python module which allows you to specify timeouts when calling any existing function, and support for stoppable threads
Stars: ✭ 146 (+370.97%)
Mutual labels:  thread
Adi
ADI(Android Debug Intensive) 是通过 JVMTI 实现的 Android 应用开发调试的增强工具集,目前主要提供性能相关的监控能力。
Stars: ✭ 194 (+525.81%)
Mutual labels:  thread
Nevercrash
🌍 全局捕获Crash。信NeverCrash,永不Crash。
Stars: ✭ 170 (+448.39%)
Mutual labels:  thread
Kommander Ios
A lightweight, pure-Swift library for manage the task execution in different threads. Through the definition a simple but powerful concept, Kommand.
Stars: ✭ 167 (+438.71%)
Mutual labels:  thread
Useworker
⚛️ useWorker() - A React Hook for Blocking-Free Background Tasks
Stars: ✭ 2,233 (+7103.23%)
Mutual labels:  thread

PooledProcessMixIn For Python

Python Logo

Fast Concurrent Pool of preforked-processes and threads Mix-in for python's socket server Replace the usual ThreadingMixIn and ForkingMixIn

This is a pure-python module that provides asynchronous mix-in similar to standard ThreadingMixIn and ForkingMixIn but provides better performance by utilizing a pool of processes forked at initialization time each process allocate a pool of given number of threads

Installation and Dependencies

This module has no external dependencies other than the standard python library.

To get the latest development snapshot type the following command

git clone https://github.com/muayyad-alsadi/python-PooledProcessMixIn.git

Example

from PooledProcessMixIn import PooledProcessMixIn
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer

# ... define MyTestHandler somewhere

class MyHTTPTest (PooledProcessMixIn, HTTPServer):
    def __init__(self):
        self._process_n=7  # if not set will default to number of CPU cores
        self._thread_n=64  # if not set will default to number of threads
        HTTPServer.__init__(self, ('127.0.0.1',8888), MyTestHandler)
        self._init_pool() # this is optional, will be called automatically
        print "listing on http://127.0.0.1:8888/"

Details

You can set initial number of processes by setting self._process_n before calling self._init_pool()

You can set initial number of threads for each forked process by setting self._thread_n before calling self._init_pool()

You should call self._init_pool() AFTER super class __init__ but if you did not call it, it will be called automatically when we get first request

When Benchmarked against ThreadingMixIn and ForkingMixIn, it gives double performance (was able to handle about 1,500 request per second while other mix-ins reached 800 requests/second )

siege -b -c 100 -t10s localhost:8888/test
      Date & Time,  Trans,  Elap Time,  Data Trans,  Resp Time,  Trans Rate,  Throughput,  Concurrent,    OKAY,   Failed
2012-08-02 12:51:47,  14663,       9.58,           0,       0.01,     1530.58,        0.00,       22.87,   14663,       0
2012-08-02 12:52:44,   7653,       9.58,           0,       0.04,      798.85,        0.00,       29.42,    7653,       5
2012-08-02 12:53:14,   7726,       9.47,           0,       0.05,      815.84,        0.00,       43.57,    7726,       0

Can I use it to run my Django applications ?

Yes, Django provides WSGI application which can be used like the wsgi-demo included in this packages

import sys, os
    
from PooledProcessMixIn import PooledProcessMixIn
from wsgiref.simple_server import make_server, WSGIServer
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    
d=os.path.dirname(__file__)
sys.path.insert(0, d)
sys.path.insert(0, os.path.join(d, ".."))
    
from django import VERSION as DJ_VERSION
if DJ_VERSION>=(1,4):
    from django.core.wsgi import get_wsgi_application
else:
    from django.core.handlers.wsgi import WSGIHandler as get_wsgi_application
    
class WSGIServerPool(PooledProcessMixIn, WSGIServer):
    pass
    
application = get_wsgi_application()
make_server('127.0.0.1', 8080, application, server_class=WSGIServerPool).serve_forever()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].