Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request [Maybe look into Using Winloop which is a uvloop alternative for Windows users] #1451

Open
Vizonex opened this issue Jun 15, 2023 · 2 comments

Comments

@Vizonex
Copy link

Vizonex commented Jun 15, 2023

The issue

Windows can be very slow with asyncio especially when invoking too many tcp connections and on top of that uvloop is not supported with windows. That was until I came along and took a crack at it myself and got it to work with changing a lot of code hence the reason for making it into a separate library in the first place. I found that my library winloop to be pretty successful at being faster than the WindowsSelectorEventLoopPolicy as well as the WindowsProactorEventLoopPolicy which the ProactorEventLoop is known to have ssl issues with version 3.9. Since TheHarvester uses a lot of tcp connections to webscrape search engines, I thought it might be a good idea if we were to go ahead and give winloop a try with this amazing software.
If you need any benchmarks, I have them in the readme of my github repository and on pypi.

Where do we use winloop?

The only place it would have to be implemented is at the beginning where theHarvester.py file is located because at the end of the day it's using window's C APIs instead of any Posix Only Apis. My idea is to try and import the winloop module after freezing multiprocessesing before falling back to using the SelectorEventLoopPolicy if winloop is unavalible or for anyone who doesn't have windows C/C++ libraries installed yet. That way those who don't want to install the C/C++ libraries can still use TheHarvester. But for those who have the C/C++ Extensions can have some performance benefits.

The Plan

Here is where I would like this to go/be and how it should go about being implemented.

if __name__ == '__main__':
    platform = sys.platform
    if platform == 'win32':
        # Required or things will break if trying to take screenshots
        import multiprocessing
        
        multiprocessing.freeze_support()
        
        # Check for asyncio performance benefits
        try:
            import winloop
            winloop.install()
        except ModuleNotFoundError:
            # Fallback to using the SelectorEventLoopPolicy
             asyncio.DefaultEventLoopPolicy = asyncio.WindowsSelectorEventLoopPolicy

Expected Outcome

I hope that by implementing this feature we can start to see faster performance and acceleration for windows users and that the speed will help benefit the tcp connections made as well as the dns lookups and hopefully there will be less drag and lag when it's collecting things and maybe some improvements with taking screenshots of specific sites.

The Systems/OS In Question

  • Windows 10 / 11
    Nothing more and nothing less :)

The Python Package and Github Repository

P.S. I'm also the developer of Winloop. If you have any problems with using this library you can forward those issues to my repository I'll be happy to take a look at them and try and solve any issues arising from it.

@NotoriousRebel
Copy link
Collaborator

This is extremely cool and I will have to look more into this. Out of curiousity, why not create a PR for uvloop and have uvloop support both windows and linux with the winloop code? I have not looked at the codebase for winloop yet but just a thought. I have also faced errors in the past when running this tool on Windows before which is why I lowered the number of asyncio tasks from 3 to 2 a while ago which seems to be more stable at least from testing the tool.

@Vizonex
Copy link
Author

Vizonex commented Jun 15, 2023

@NotoriousRebel
I would love to do that with uvloop but the problem is that it would be really hard to compile as well as figure it out.
There were a couple of libraries and a dozen functions that had to be dropped out or replaced. But I'll definitely try to merge my project to uvloop in the future but it will be an entire obstacle of it's own. Many system checks would need to be in place in order to make it work. But thank you for the suggestion I'll try to reach out again to the Magicstack team on how winloop can be implemented in uvloop in a clean manner. Let me know if you still want me to make a pull request for implementing winloop until uvloop has support for windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants