vibora icon indicating copy to clipboard operation
vibora copied to clipboard

Exception ignored in: 'vibora.responses.responses.Response.send'

Open sharkguto opened this issue 6 years ago • 0 comments

Describe the bug

First of all, I would like to thank you for the excellent work in vibora framework. So... just a explanation about this "bug". I am doing some benchmarks before change my application from sanic to vibora, and I do massive requests to get data from a postgresql database.

my api returns the expected value but i got some exceptions from Request.send... I believe this is not should be a bug, but i want to suppress that following message: Exception ignored in: 'vibora.responses.responses.Response.send'

Is it a bug, or am i doing something wrong?

Exception ignored in: 'vibora.responses.responses.Response.send'
Traceback (most recent call last):
  File "uvloop/handles/stream.pyx", line 671, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 165, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x1fe8258>; the handler is closed

This impact the benchmark test.

response result

gustavo@localhost:~/Documents/teste_carga$ curl http://127.0.0.1:5000/db2
[{"salary":2.0999999046,"address":"n","age":2,"id":10,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":9,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":8,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":7,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":6,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":5,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":4,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":3,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":2,"name":"b"},{"salary":2.0999999046,"address":"n","age":2,"id":1,"name":"b"}]

To Reproduce Steps to reproduce the behavior:

============= api code ==========================================

from vibora import Vibora, JsonResponse, Response
from asyncpg import create_pool
from vibora.hooks import Events
import logging


app = Vibora(log_handler=None)

DB_CONFIG = {
    "host": "127.0.0.1",
    "user": "gustavo",
    "password": "test",
    "port": "5432",
    "database": "test",
}

# Config will be a new component.


class Config:
    def __init__(self):
        self.name = "Vibora Component postgresql"

    def set_pool(self, pool):
        self.pool = pool


def jsonify(records):
    """
    Parse asyncpg record response into JSON format
    """
    # print(records)
    list_return = []

    for r in records:
        itens = r.items()
        list_return.append(
            {i[0]: i[1].rstrip() if type(i[1]) == str else i[1] for i in itens}
        )
    return list_return


@app.handle(Events.BEFORE_SERVER_START)
async def before_start():
    pool = await create_pool(**DB_CONFIG, max_size=20)
    cfg = Config()
    cfg.set_pool(pool)
    app.components.add(cfg)


@app.route("/db2", methods=["GET"])
async def home(postg: Config):
    async with postg.pool.acquire() as conn:
        results = await conn.fetch(
            "SELECT salary,address,age,id,name FROM test.company"
        )
        results = jsonify(results)
    return JsonResponse(results)


@app.route("/", methods=["GET"])
async def home2():
    return Response(b"hello world!")


if __name__ == "__main__":

    app.run(debug=False, host="0.0.0.0", port=5000, workers=4)


===================== postgresql structure table =========================

create schema test;
CREATE TABLE test.COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
);
select * from test.company;
insert into test.company values(10,'b',2,'n',2.1);
insert into test.company values(9,'b',2,'n',2.1);
insert into test.company values(8,'b',2,'n',2.1);
insert into test.company values(7,'b',2,'n',2.1);
insert into test.company values(6,'b',2,'n',2.1);
insert into test.company values(5,'b',2,'n',2.1);
insert into test.company values(4,'b',2,'n',2.1);
insert into test.company values(3,'b',2,'n',2.1);
insert into test.company values(2,'b',2,'n',2.1);
insert into test.company values(1,'b',2,'n',2.1);
select count(*) from pg_catalog.pg_stat_activity;
select * from pg_catalog.pg_stat_activity;

========================== loading tests ================================

gustavo@localhost:~/Documents/teste_carga$ wrk -c 512 http://127.0.0.1:5000/db2
Running 10s test @ http://127.0.0.1:5000/db2
  2 threads and 512 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   139.27ms  137.08ms   1.38s    87.17%
    Req/Sec     2.23k   360.80     2.93k    70.00%
  44449 requests in 10.06s, 31.83MB read
  Socket errors: connect 0, read 0, write 0, timeout 1
Requests/sec:   4417.01
Transfer/sec:      3.16MB
gustavo@localhost:~/Documents/teste_carga$

========================vibora running =================================

gustavo@localhost:~/Documents/teste_carga$ pythonbench_vibora.py
# Vibora (0.0.7) # http://0.0.0.0:5000

Exception ignored in: 'vibora.responses.responses.Response.send'
Traceback (most recent call last):
  File "uvloop/handles/stream.pyx", line 671, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 165, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x1fab5f8>; the handler is closed
Traceback (most recent call last):
  File "uvloop/handles/stream.pyx", line 671, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 165, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x1fe8258>; the handler is closed
Exception ignored in: 'vibora.responses.responses.Response.send'
Traceback (most recent call last):
  File "uvloop/handles/stream.pyx", line 671, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 165, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x1fe8258>; the handler is closed

Expected behavior Should show no errors or suppress those exception messages

sharkguto avatar Jul 30 '18 19:07 sharkguto