Giter Club home page Giter Club logo

pulsar's Introduction

Pulsar

|

Badges

license pyversions status pypiversion contributors

CI

circleci coverage appveyor travis docs

Documentation

https://docs.pulsarweb.org

Downloads

http://pypi.python.org/pypi/pulsar

Source

https://github.com/quantmind/pulsar

Benchmarks

https://bench.pulsarweb.org/

Chat channel

Riot.im room

Mailing list

google user group

Stack overflow

questions tagged python-pulsar

Design by

Quantmind and Luca Sbardella

Platforms

Linux, OSX, Windows. Python 3.5 and above

Keywords

python, asyncio, multiprocessing, client/server, asynchronous, concurrency, actor, thread, process, socket, wsgi, websocket, redis, json-rpc

An example of a web server written with pulsar which responds with "Hello World!" for every request:

from pulsar.apps import wsgi

def hello(environ, start_response):
    data = b'Hello World!\n'
    response_headers = [
        ('Content-type','text/plain'),
        ('Content-Length', str(len(data)))
    ]
    start_response('200 OK', response_headers)
    return [data]


if __name__ == '__main__':
    wsgi.WSGIServer(callable=hello).start()

Pulsar's goal is to provide an easy way to build scalable network programs. In the Hello world! web server example above, many client connections can be handled concurrently. Pulsar tells the operating system (through epoll or select) that it should be notified when a new connection is made, and then it goes to sleep.

Pulsar uses the asyncio module from the standard python library and it can be configured to run in multi-processing mode.

Another example of pulsar framework is the asynchronous HttpClient:

from pulsar.apps import http

async with http.HttpClient() as session:
    response1 = await session.get('https://github.com/timeline.json')
    response2 = await session.get('https://api.github.com/emojis.json')

The http client maintains connections alive (by default 15 seconds) and therefore any requests that you make within a session will automatically reuse the appropriate connection. All connections are released once the session exits the asynchronous with block.

Installing

Pulsar has one hard dependency:

install via pip:

pip install pulsar

or download the tarball from pypi.

To speedup pulsar by a factor of 2 or more these soft dependencies are recommended

Applications

Pulsar design allows for a host of different asynchronous applications to be implemented in an elegant and efficient way. Out of the box it is shipped with the the following:

Examples

Check out the examples directory for various working applications. It includes:

Design

Pulsar internals are based on actors primitive. Actors are the atoms of pulsar's concurrent computation, they do not share state between them, communication is achieved via asynchronous inter-process message passing, implemented using the standard python socket library.

Two special classes of actors are the Arbiter, used as a singleton, and the Monitor, a manager of several actors performing similar functions. The Arbiter runs the main eventloop and it controls the life of all actors. Monitors manage group of actors performing similar functions, You can think of them as a pool of actors.

Pulsar Actors

More information about design and philosophy in the documentation.

Add-ons

Pulsar checks if some additional libraries are available at runtime, and uses them to add additional functionalities or improve performance:

  • greenlet: required by the pulsar.apps.greenio module and useful for developing implicit asynchronous applications
  • uvloop: if available it is possible to use it as the default event loop for actors by passing --io uv in the command line (or event_loop="uv" in the config file)
  • httptools: if available, the default Http Parser for both client and server is replaced by the C implementation in this package
  • setproctitle: if installed, pulsar can use it to change the processes names of the running application
  • psutil: if installed, a system key is available in the dictionary returned by Actor info method
  • python-certifi: The HttpClient will attempt to use certificates from certifi if it is present on the system
  • ujson: if installed it is used instead of the native json module
  • unidecode: to enhance the slugify function

Running Tests

Pulsar test suite uses the pulsar test application. To run tests:

python setup.py test

For options and help type:

python setup.py test --help

flake8 check (requires flake8 package):

flake8

Contributing

Development of pulsar happens at Github. We very much welcome your contribution of course. To do so, simply follow these guidelines:

  • Fork pulsar on github
  • Create a topic branch git checkout -b my_branch
  • Push to your branch git push origin my_branch
  • Create an issue at https://github.com/quantmind/pulsar/issues with pull request for the dev branch.
  • Alternatively, if you need to report a bug or an unexpected behaviour, make sure to include a mcve in your issue.

A good pull request should:

  • Cover one bug fix or new feature only
  • Include tests to cover the new code (inside the tests directory)
  • Preferably have one commit only (you can use rebase to combine several commits into one)
  • Make sure flake8 tests pass

License

This software is licensed under the BSD 3-clause License. See the LICENSE file in the top distribution directory for the full license text.

pulsar's People

Contributors

artemmus avatar bright-pan avatar cyberj avatar davidjfelix avatar dhutty avatar etataurov avatar eventh avatar fabiocerqueira avatar felippemr avatar keis avatar lsbardel avatar pvanderlinden avatar remcoder avatar robgil avatar ryankung avatar s-sokolko avatar sekrause avatar wilddom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pulsar's Issues

Better get_stream function

The function accept a config dictionary and return a stream object to write information without using the actor logger.
It is implemented in the pulsar.async.actor module.
All print function calls should be removed from the code.

Tasks to create new tasks

Some tasks are quite big, expecially periodic tasks which perform massive updates on data.

An idea could be to have periodic tasks which send tasks requests.

A map reduce framework.

Thread pool

Actor to have a thread pool implementation so that CPU type workers can have more than one thread to work on.

recursive behaviour in MultiDeferred

The MultiDeferred class has a recursive behaviour on Mapping, list, sets and generators.
Should this made optional, with default false?
It caused a bug in the test suite returning a list of errors.

Deferred returning deferred

Deferred returning deferred needs to have test put in place. Their behaviour is quite complex and difficult to follow.

I/O loop callbacks not called

When errors occurs, looping callbaks are not called and they keep getting added to the event loop slowing down the server response.

Link newly created monitors

When a new monitor is created with the arbiter has already started, the other monitors are not linked with it.
This is the proposal:

  • When a new monitor is created, it should link with existing monitors.
  • Existing monitors should pass the information to their existing actors.
  • The new actors will be aware of the link automatically.

Memory leaks in generators

Generators can cause memory leaks, visible using the --show_leaks test option.
In particular the async.actor tests cause leaks the the mailbox _responde generator

spawn to return a deferred

The pulsar.spawn method should return a deferred rather than a proxy. The deferred will receive the callback once the actor is fully operational. That is to say, the actor has registered its mailbox address with the ActorProxyMonitor.

test plugins options

The command options of plugins which are not installed are available in the command line. They shouldn't.

contributing page in docs

Write up a doc page documenting how best to contribute to pulsar development.
The page is in docs/source/contributing.rst

SocketIO middleware

The websocket application works for Chrome and Firefox.
A new web socket middleware is needed to cover most web browsers.
The best solution seems the SocketIO protocol.

New deferred implementation

Modify the current deferred implementation so that you can add error backs as well as callbacks. Exactly the same way as twisted.

pep 3156

Changes of internals to accommodate pep 3156

Worker thread

CPU bound workers can take a long time to process a request.
In this case we should have a dedicated thread in the worker process which communicate with the arbiter.
This is to be implemented for workers on a separate process.

Problem with RPC example on Python3.3.

I'm getting the following error:

2013-01-13 07:05:44 [p=1516,t=140735145521536] [ERROR] [pulsar.iostream] Could not parse data Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pulsar/async/iostream.py", line 762, in request_data parsed_data, buffer = self.parser.decode(buffer) File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pulsar/apps/wsgi/server.py", line 327, in decode self.expect_continue() File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pulsar/apps/wsgi/server.py", line 345, in expect_continue if headers is not None and headers.get('Expect') == '100-continue': AttributeError: 'list' object has no attribute 'get'

The cause is line https://github.com/quantmind/pulsar/blob/0.4/pulsar/apps/wsgi/server.py#L345. (At least, the AttributeError, I'm not sure if the "Could not parse data) is or not.

Coverage test plugin

Currently to check test coverage we need to run tests in thread mode so that coverage can be collected.
We need a test coverage plugin using the coverage API in the same line as the profile test plugin.

exclude tag option in tests

To add an exclude option when running tests:

python runtests.py --exclude apps calculator

In the example the tests with labels apps and calculator won't run.

pattern importing

Importing modules using a pattern such as tests or test_* is working but all modules are imported first.
Modules not matching the pattern should not be imported.

Asynchronous Tasks

At the moment task-queue workers process a task at a time in a synchronous way.
Propose to:

  • Allow for asynchronous behavoiur by yielding and releasing the event loop
  • Process a maximum number of task concurrently by using max_concurrent_tasks configuration parameter.

better method for is_trace_back

Currently I use this

def is_stack_trace(trace):
    if isinstance(trace,tuple) and len(trace) == 3:
        return True
    return False

But should I use

inspect.istraceback(trace)

Fix may_pool_task

The may_pool_task method in the TaskBackend periodically call itself every 1 second, to pull new tasks. Is this the best way?

Profiling task

Add functionality to profile a task run using the python profiler.

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.