choleraehyq / aiorpc Goto Github PK
View Code? Open in Web Editor NEWA fast python rpc library based on asyncio and MessagePack
License: Do What The F*ck You Want To Public License
A fast python rpc library based on asyncio and MessagePack
License: Do What The F*ck You Want To Public License
In Python 3.10, for many of asyncio's higher-level functions, the loop
parameter got removed.
Consequently, aiorcp
yields TypeError: create_connection() got an unexpected keyword argument 'loop'
.
One responsible line seems to be in client.py
: await asyncio.open_connection(self._host, self._port, loop=self._loop)
I think it would be awesome if there was a way to define what kind of input a function takes, if it's required, and a way to enforce the type (i.e. str, int). Of the top of my head, we could do something like this:
@aiorpc.method({
'id': [str, True],
'ttl': [int, False, 86400]
})
async def set_ttl(payload):
...
All decorated functions would be registered as methods, and the provided dict would list the name of the arguments, and then the value would be a list- Type, Required, Default (optional). On the backend we could implement our own validation logic or build json schema objects on the fly.
I see two advantages:
Thoughts?
When the wait_for for the callback of an async function times out an exception is raised. It's then sent over to the client.
However, the info from the exception is extracted using 'str' (server.py:165):
await _send_error(conn, str(e), msg_id)
which returns None, ultimately raising no exception at the client.
Change 'str' to 'repr', for instance, will correctly cause an exception to be raised in the client side.
This package is deprecated. Install msgpack instead.
https://pypi.org/project/msgpack-python/
When users install both msgpack and aiorpc they will have both msgpack and msgpack-python installed, which conflict.
Metrics describing method performance would be nice.
I'm thinking of having a common function, such as _trace
that takes a metric name (like aiorpc.server.request.duration
), a dict of tags, type (timing, gauge), and a value (for timing).
Then you could call set_metric_backend
with either aiorpc.metrics.dogstatsd
or aiorpc.metrics.statsd
. I think default will be dogstatsd, as datadog (and other hosted solutions) and telegraf support dogstatsd type tags.
When you encounter an internal exception, such as a msgpack exception saying it can't serialize a string, the server doesn't send anything to the client- it just times out.
This is not ideal behavior and should be fixed.
Is there a standard being following here?
I'm asking because I'm making some improvements for my own use, such as improved exception handling, which are changing some parts of the payload being sent back and forth. I'd love to merge them back in, but if there is a standard being followed I don't want to break it.
I have been trying this library out, and it seems perfect for what we need.
However, whenever a client calls any function on the servers the logs are filled with the following error:
ERROR:aiorpc.aiorpc.server:Exception object of type 'NoneType' has no len() raised when _parse_request None
2018-05-23 15:26:14,108 aiorpc.aiorpc.server ERROR Timeout when _send_error 'NoneType' object has no attribute '__call__' to ('127.0.0.1', 62243)
ERROR:aiorpc.aiorpc.server:Timeout when _send_error 'NoneType' object has no attribute '__call__' to ('127.0.0.1', 62243)
I get many of those entries every second.
Any idea what's wrong?
PyPy support would be cool
API Timeout when calling an invalid function and using Class Based methods.
Using the following code example
from aiorpc import RPCClient
import asyncio
import uvloop
import time
async def do(cli):
await client.call('test_method', 'abc')
time.sleep(5)
await client.call('test_method', 'abc')
loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)
client = RPCClient('127.0.0.1', 6000)
loop.run_until_complete(do(client))
client.close()
Will cause the server to freak out, eating up RAM and CPU until the client closes the connection. I would recommend adding a timeout on the server side.
The latest version on PyPi is v0.1.3, published two years ago on May 12, 2018.
Awesome features are missing from v0.1.3., like async with
.
Thanks!
Client:
for i in range(0, 20):
loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)
client = RPCClient('proxy', 6000, timeout=100)
loop.run_until_complete(do(client))
# client.close() <-- specifically don't close connection for reproduce
import time
time.sleep(100)
You catch memory overflow and 100% of CPU loading after 10-20 seconds. Seems like you have a problem here aiorpc/server.py:124
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.