This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> timeit.timeit("""json.dumps({"name": "foo", "id":1})""", setup="from __main__ import json", number=10000) | |
0.04011281501152553 | |
>>> timeit.timeit("json_format.MessageToJson(person)", setup="from __main__ import json_format, person", number=10000) | |
0.2599130409944337 | |
>>> person | |
name: "foo" | |
id: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import contextvars | |
import uvloop | |
from types import SimpleNamespace | |
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | |
trace_context = contextvars.ContextVar('trace_context') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import contextvars | |
import uvloop | |
from types import SimpleNamespace | |
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | |
N = 100000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import contextvars | |
import uvloop | |
from types import SimpleNamespace | |
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | |
trace_context = contextvars.ContextVar('trace_context') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aioredis | |
import asyncio | |
import json | |
from aiohttp import web | |
tasks = {} | |
task_id = 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import sys | |
async def foo(): | |
pass | |
async def test(): | |
t = asyncio.tasks.create_task(foo()) | |
print(sys.getsizeof(t)) | |
print(id(t)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 3.7.0b1 (v3.7.0b1:9561d7f501, Jan 30 2018, 19:10:11) | |
[Clang 6.0 (clang-600.0.57)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import contextvars | |
>>> foo = contextvars.ContextVar("foo") | |
>>> foo.set("a") | |
<Token var=<ContextVar name='foo' at 0x10ccbe2b0> at 0x10ccc36c0> | |
>>> bar = contextvars.ContextVar("bar", default="b") | |
>>> list(contextvars.copy_context().keys()) | |
[<ContextVar name='foo' at 0x10ccbe2b0>] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import timeit | |
class Object: | |
def __init__(self, x): | |
self.x = x | |
class Rule: | |
def __init__(self, valid_values, valid_values2): | |
self.valid_values = valid_values | |
self.valid_values2 = valid_values2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def request_start(session, trace_context, method, host, port, headers): | |
trace_context.start = loop.time() | |
headers['X-Request-id'] = 'request_id' | |
async def request_stop(session, trace_context, response): | |
print("request type {}".format(trace_context.query)) | |
print("request finsihed with {} status code".format(response.status_code)) | |
print("request took {}".format(loop.time() - trace_context.start)) | |
async def request_exception(session, trace_context, exc): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MetricsClient(ClientSession): | |
def __init__(self, metric_name, region, **kwargs): | |
self(MetricsClient, self).__init__( | |
self, | |
*args, | |
request_tracing=True, | |
request_tracing_ctx=dict | |
**kwargs) | |
self.metric_name = metric_name |