registers the end of a request

    registers the end of a request, computes elapsed time, sends it to the collector

    :param req: request, can be mostly any hash-able object
    :param collector_addr: collector address, in zeromq format (string, default tcp://127.0.0.2:2345)
    :param prefix: label under which to register the request (string, default my_app)

def end_request(req, collector_addr='tcp://127.0.0.2:2345', prefix='my_app'):
    """
    registers the end of a request

    registers the end of a request, computes elapsed time, sends it to the collector

    :param req: request, can be mostly any hash-able object
    :param collector_addr: collector address, in zeromq format (string, default tcp://127.0.0.2:2345)
    :param prefix: label under which to register the request (string, default my_app)
    """

    req_end = time()
    hreq = hash(req)

    if hreq in requests:
        req_time = req_end - requests[hreq]
        req_time *= 1000

        del requests[hreq]

        collector = get_context().socket(zmq.PUSH)

        collector.connect(collector_addr)
        collector.send_multipart([prefix, str(req_time)])
        collector.close()

        return req_time