-
-
Save sevdog/b70bb51bafff16a7a79630139d853b32 to your computer and use it in GitHub Desktop.
Profile django-channels redis
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 yappi | |
from channels.generic.websocket import AsyncWebsocketConsumer | |
yappi.set_clock_type("WALL") | |
class EchoProfileConsumer(AsyncWebsocketConsumer): | |
async def connect(self): | |
await self.accept() | |
#print(f'Connect {self.scope["client"]} to {self.channel_name}') | |
await self.channel_layer.group_add("test", self.channel_name) | |
async def disconnect(self, close_code): | |
await self.channel_layer.group_discard("test", self.channel_name) | |
async def receive(self, text_data=None, bytes_data=None): | |
with yappi.run(): | |
await self.channel_layer.group_send( | |
"test", | |
{ | |
"type": "chat.message", | |
"text": text_data | |
} | |
) | |
yappi.get_func_stats().print_all(columns={ | |
0: ("name", 64), # need a long length to avoid trim | |
1: ("ncall", 5), | |
2: ("tsub", 8), | |
3: ("ttot", 8), | |
4: ("tavg", 8) | |
}) | |
async def chat_message(self, event): | |
await self.send(event["text"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment