HTTP/2优先级& Jetty的依赖测试 [英] HTTP/2 priority & dependency test with Jetty

查看:134
本文介绍了HTTP/2优先级& Jetty的依赖测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

优先级和依赖关系:

在这里,我做了简单的测试.但是结果似乎不太好. 我试图在同一连接的for循环中发出100个请求(请求url是相同的,我想知道这部分是否会影响结果).

Here I made I simple test. But the result seems not so good. I tried to make 100 request in a for loop in the same connection(the request url is the same, I am wondering whether this part influence the results).

如果索引为i,则我的请求stream_id为i,而从属stream_id为100 + i.如果我们的假设正确,那么请求就永远不会得到响应,因为从101到200之间没有stream_id.

If the index is i, then my request stream_id is i while the dependent stream_id is 100+i. If our assumption is right, the request can never get response because there is no stream_id from 101 to 200.

但是结果表明,设置依赖关系没有区别.我得到的响应数据帧是一个接一个的,没有超时或等待. 以及其他一些相关的测试,起点是让依赖于其他流的流首先被发送,然后依赖于流.但是结果是一样的. 我仍在思考结果的原因.谁能帮我?非常感谢.

But the results shows there is no difference for setting the dependency and not. I got the response data frame one by one without timeout or waiting. And also some other related test, the start point is to let the stream which depends on other stream to be sent first and the stream dependent later. But the result is same. I am still thinking the reason of the results. Can anyone help me? Many thanks.

此处的代码:

public void run() throws Exception
{
    host = "google.com";
    port = 443;
    //client init
    HTTP2Client client = new HTTP2Client();
    SslContextFactory sslContextFactory = new SslContextFactory(true);
    client.addBean(sslContextFactory);
    client.start();       

    //connect init
    FuturePromise<Session> sessionPromise = new FuturePromise<>();
    client.connect(sslContextFactory, new InetSocketAddress(host, port), new ServerSessionListener.Adapter(), sessionPromise);
    Session session = sessionPromise.get(10, TimeUnit.SECONDS);

    //headers init
    HttpFields requestFields = new HttpFields();
    requestFields.put("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);

    final Phaser phaser = new Phaser(2);

    //multiple request in one connection
    for(int i=0;i<100;i++)
    {
        MetaData.Request metaData = new MetaData.Request("GET", new HttpURI("https://" + host + ":" + port + "/"), HttpVersion.HTTP_2, requestFields);
        PriorityFrame testPriorityFrame = new PriorityFrame(i, 100+i, 4, true);
        HeadersFrame headersFrame = new HeadersFrame(0, metaData, testPriorityFrame, true);

        //listen header/data/push frame
    session.newStream(headersFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter()
    {
        @Override
        public void onHeaders(Stream stream, HeadersFrame frame)
        {
            System.err.println(frame+"headId:"+frame.getStreamId());
            if (frame.isEndStream())
                phaser.arrive();
        }

        @Override
        public void onData(Stream stream, DataFrame frame, Callback callback)
        {
            System.err.println(frame +"streamid:"+ frame.getStreamId());
            callback.succeeded();
            if (frame.isEndStream())
                phaser.arrive();
        }

        @Override
        public Stream.Listener onPush(Stream stream, PushPromiseFrame frame)
        {
            System.err.println(frame+"pushid:"+frame.getStreamId());
            phaser.register();
            return this;
        }


    });
    }
    phaser.awaitAdvanceInterruptibly(phaser.arrive(), 5, TimeUnit.SECONDS);

    client.stop();
}

推荐答案

Jetty项目尚未实现(但尚未实现)HTTP/2请求优先级.

The Jetty project did not implement (yet) HTTP/2 request prioritization.

我们正在讨论这是否对服务器有用,服务器关心的是尽快写回响应.

We are discussing whether this is any useful for a server, whose concern is to write back the responses as quick as it can.

让一个客户改变请求的优先级,或者发出一个请求,即知道实际上它首先希望另一个请求得到服务,这对于服务器来说是很多工作,同时还必须为其他10,000个客户提供服务连接到它.

Having one client changing its mind on the priority of the requests, or making a request knowing that in reality it first wanted another request served, it's a lot of work for the server that in the meantime has to serve the other 10,000 clients connected to it.

当服务器重新为相关请求重新计算优先级树时,它可能已经为请求提供服务了.

By the time we the server has recomputed the priority tree for the dependent requests, it could have probably have served the requests already.

当客户意识到必须更改请求的优先级时,对该请求的整个响应可能已经在执行中.

By the time the client realizes that it has to change the priority of a request, the whole response for it could already be in flight.

话虽如此,我们当然对在现实世界中的用例感兴趣,在这些用例中,服务器执行的请求优先级排序可以带来真正的性能提升.我们只是还没有看到它.

Having said that, we are certainly interested in real world use cases where request prioritization performed by the server yields a real performance improvement. We just have not seen it yet.

我很想听听您为什么对请求优先级感兴趣以及如何利用它.您的答案可能是推动Jetty项目实现HTTP/2优先级的驱动力.

I would love to hear why you are interested in request prioritization and how you are leveraging it. Your answer could be a drive for the Jetty project to implement HTTP/2 priorities.

这篇关于HTTP/2优先级&amp; Jetty的依赖测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆