Coder Social home page Coder Social logo

Performance Tuning about hyper HOT 18 OPEN

python-hyper avatar python-hyper commented on August 17, 2024
Performance Tuning

from hyper.

Comments (18)

Lukasa avatar Lukasa commented on August 17, 2024

The first two points should provide a huge performance boost if handled appropriately.

from hyper.

schlamar avatar schlamar commented on August 17, 2024

I just wanted to come here and propose point number 1 after reading your noteboook and then found out that you are already thinking about it :) I can confirm that reading a block into a buffer is a significant improvement on a proprietary TCP protocol with sized framing.

Right now the buffer is a simple string which gets expanded after socket.recv. But there might be more efficient alternatives. Maybe socket.recv_info can be used with a StringIO or something like that. Do you have some ideas for an efficient buffer implementation? Anything that helps with point two would be great. :)

from hyper.

dimaqq avatar dimaqq commented on August 17, 2024

On a related note, please be more thorough than time.time(), for example:

if sys.platform.lower().startswith("linux"):
    def _rusage():
        tmp = resource.getrusage(1)  # RUSAGE_THREAD
        return dict(time=time.time(),    # wall
                    utime=tmp.ru_utime,  # user
                    stime=tmp.ru_stime,  # system
                    switch=tmp.ru_nivcsw * 1.,   # cpu contention
                    read=tmp.ru_inblock * 512.,  # disk io
                    write=tmp.ru_oublock * 512.,
                    fault=tmp.ru_majflt * 1.)    # memory contention

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

@dimaqq Good advice, though I was running the notebook on OS X, which would have limited the utility of that function. Might be worth me going back and adding it just for those who run on other platforms though, I'll have a think.

@schlamar I'm not yet sure, I don't know enough about efficient buffers in Python. Note sure that StringIO will work though, because I think the buffer you pass to the recv_into call needs to be a memoryview. You could have a bytearray and a memoryview to it, and use that. This would lead to, as an initial step, a very simple userspace-buffered socket.

More ideally we'd like to be able to use a fixed-size buffer as a ring buffer. I've never seen this done in Python, let-alone in pure Python, and I don't know that it's possible. I'll need to think about how I'd pull it off.

from hyper.

sigmavirus24 avatar sigmavirus24 commented on August 17, 2024

@Lukasa do you really want a ring buffer? If I remember correctly, won't it write over old data in the buffer it isn't read quickly enough?

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

The general plan is no. =) socket.recv_into only reads in as much data as there is space in the buffer. It should in principle be possible to have that number be equivalent to the amount of space left in the actual ring buffer.

Of course, that's almost certainly impossible to do without C extensions, which I can't do. So it'll be easier to do as a single linear buffer.

from hyper.

sigmavirus24 avatar sigmavirus24 commented on August 17, 2024

For what it's worth, I can think of a way to enforce that with a BytesIO buffer (thanks requests-toolbelt) if you're supposed to be reading bytes. (The same logic would work for a StringIO buffer too)

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

Sadly, I don't think you can use BytesIO with a memoryview, which means I can't use socket.recv_into, which means I can't avoid the overhead of an extra memory copy.

from hyper.

dimaqq avatar dimaqq commented on August 17, 2024

guys, I think this socket reading conversation is moot.
http/2 is (supposedly) meant to be used over TLS...

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

TLS still uses sockets. =)

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

It's also totally allowed to use HTTP/2 in plaintext. =)

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

The buffered socket idea has been implemented: see this diff.

I've also added some more optimisation ideas, contained in issues #60 and #61.

from hyper.

sigmavirus24 avatar sigmavirus24 commented on August 17, 2024

Do we have any benchmarks showing the performance benefits? (Call me a pain if you will ;P)

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

Not yet, but I plan to re-run my big HTTP/1.1 - HTTP/2 comparison at some point to see how the numbers change.

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

In the meantime, pypy's test run speed got a big boost when I fixed the tests up, so anecdotally it 'feels' faster.

from hyper.

sigmavirus24 avatar sigmavirus24 commented on August 17, 2024

I didn't doubt it was faster. I was just trying to pre-empt some people from finding this and complaining about lack of benchmarks.

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

Agreed, I'll try to get some numbers. =)

from hyper.

Lukasa avatar Lukasa commented on August 17, 2024

Support for nghttp2's HPACK implementation is now present.

from hyper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.