GithubHelp home page GithubHelp logo

Comments (5)

az75014 avatar az75014 commented on June 19, 2024 1

Sure! To prove to myself that adding pooling would make the difference for me I created a MyAsyncImage/myasyncimage.py so that I could make it load my hacky MyLoader/myloader.py rather than the Kivy code one. It was basically copy/paste, apart from the changes indicated below.

This was just a test, I'm sure it needs more thought than this.

...
import urllib3
pool_mgr = urllib3.PoolManager(maxsize=10)
"""
Note: I set maxsize to 10 because I was getting warnings due to too many concurrent requests:
[WARNING] [Connection pool is full, discarding connection]
I tested this with a value of 1000 also with seemingly no ill effect. 
Maybe it should match the Loader.num_workers value? 
It's set to 10 in my case as the images I am loading are rather small.
I left num_pools unchanged as not relevant in my case: there was only ever going to be 1 pool,
namely the connection to my image server. (default is 10)
"""
Cache.register('kv.loader', limit=500, timeout=500)
...
    def _load_urllib(self, filename, kwargs):
        '''(internal) Loading a network file. First download it, save it to a
        temporary file, and pass it to _load_local().'''	
        import tempfile
        global pool_mgr
        if not pool_mgr:
            pool_mgr = urllib3.PoolManager(maxsize=10)
...
        try:
            _out_filename = ''
            """
            Note: in my hacked version I removed a whole section here about smb, 
            headers, custom context as not relevant to my test
            """
            fd = pool_mgr.request("GET", filename)

            if '#.' in filename:
                # allow extension override from URL fragment
                suffix = '.' + filename.split('#.')[-1]
            else:
                ctype = fd.headers['Content-Type']
...
            idata = fd.data
            # removed: fd.close()
            # removed: fd = None
...

from kivy.

Julian-O avatar Julian-O commented on June 19, 2024

I am working on a refactor of loader.py in the background, so listening with interest. Do you want to share the changes you tried?

from kivy.

NomadDemon avatar NomadDemon commented on June 19, 2024

And how it behave when you change default network backend to "requests"? Its single line in config file

Can someone benchmark it?

from kivy.

az75014 avatar az75014 commented on June 19, 2024

The loader.py currently doesn't use the config file settings (apart from user agent) -- urlib.request is hardcoded.

There is no session mechanism for the "requests" implementation, so that shouldn't make a difference?

On my app I make several requests to my API on start up, I had a huge efficiency boost after I implemented sessions for that.

Currently, I create a session in my App class, save it as a class attribute and then pass the session object as an argument to e.g. my API request module. It works fine but seems a bit hacky to do it this way.

There might be scope to handle this better?

from kivy.

NomadDemon avatar NomadDemon commented on June 19, 2024

The loader.py currently doesn't use the config file settings (apart from user agent) -- urlib.request is hardcoded.

There is no session mechanism for the "requests" implementation, so that shouldn't make a difference?

On my app I make several requests to my API on start up, I had a huge efficiency boost after I implemented sessions for that.

Currently, I create a session in my App class, save it as a class attribute and then pass the session object as an argument to e.g. my API request module. It works fine but seems a bit hacky to do it this way.

There might be scope to handle this better?

it uses

Try

Config.set("network", "implementation", "requests")

it should work from kivy 2.2.0

implementation_map = {

from kivy.

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.