Giter Site home page Giter Site logo

pyancillary's Introduction

pyancillary

Pyancillary is async networking library for python, best performs on pypy.

why?

Pyancillary is multi process and concurrent. Unlike node cluster module that allows the operating system to do load balancing between process’s, Pyancillary equally distributes the load across all process’s evenly. This is vital since in a node cluster single process can accept a connection during high load when that connection could have been better served by another process which might have been dealing with 0 concurrent connections. Relying on the operating system for load balancing is inefficient when multiple cores are at your disposal

install:

$ git clone https://github.com/YuaShizuki/pyancillary.git
$ pypy setup.py install

example:

# simple hello world http server
import pyancillary.load_balancer as lb
import pyancillary.asock as asock
import os

def Handler(connection, address):
    request_header = yield connection.recv_p("\r\n\r\n")
    print "PID(%d) recived header =>\n%s\n" % (os.getpid(), request_header.strip())
    connection.send("HTTP/1.1 200 OK\r\n")
    connection.send("Content-Type: text/html; charset=UTF-8\r\n")
    connection.send("Connection: close")
    connection.send("Content-Length: 21\r\n\r\n")
    connection.send("<h1>hello_world</h1>\n")
    connection.close()
                                    
if __name__ == "__main__":
    lb.LoadBalancerLaunch(80, Handler)

explanation:

  • def Handler(connection, address) is the function called for every new connection accepted on port 80 (http).

  • connection is a asock (Awesome Socket) instance. Asock is detailed in asock.py

  • yield connection.recv_p('\r\n\r\n') yields when patter '\r\n\r\n' is recived in socket buffer. Hence in this case recives data till the end of http header.

  • thats it folks, enjoy, email me at [email protected]

pyancillary's People

Contributors

yuashizuki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.