Starting the CherryPy server multi-threaded #11

Closed
opened 2013-08-15 08:48:55 +00:00 by j1z0 · 1 comment
j1z0 commented 2013-08-15 08:48:55 +00:00 (Migrated from github.com)

As it stands now the CherryPy Server started by the DjangoHTTPContext.start_server() function is hardcoded to only have one thread in the thread pool. This is probably not much of an issue when running unit tests, but I'm trying to use this to run gui tests with selenium against multiple browsers. This can cause things to run really slowly. Consider the following code snippet.

def onBrowser(webdriver):
    class BrowserTests(DjangoHTTPContext):

        def topic(self):
            browser = webdriver()
            browser.get(self.get_url("/"))
            return browser

        def should_prompt_the_user_with_a_login_page(self, topic):
            expect(topic.title).to_include('Django')

    return BrowserTests

@Vows.batch
class TDDDjangoApp(DjangoHTTPContext):

    def get_settings(self):
        return "tddapp.settings"

    def topic(self):
        self.start_server()

    class OnChrome(onBrowser(webdriver.Chrome)):
        pass

    class OnFirefox(onBrowser(webdriver.Firefox)):
        pass

    class OnPhantonJS(onBrowser(webdriver.PhantomJS)):
        pass

On my machine this takes about 22 seconds. I could of course create the server inside of each child context but that just seems wasteful. So I would like the ability to pass in the threadcount to the start_server function so I can use the same code but start the server with multiple threads. Then performance will be greatly improved.... roughly 1.8 seconds on my machine.

I'll submit a pull request with the change, this issue is to document the purpose of that pull request.

Thanks,
Jeremy

As it stands now the CherryPy Server started by the DjangoHTTPContext.start_server() function is hardcoded to only have one thread in the thread pool. This is probably not much of an issue when running unit tests, but I'm trying to use this to run gui tests with selenium against multiple browsers. This can cause things to run really slowly. Consider the following code snippet. ``` python def onBrowser(webdriver): class BrowserTests(DjangoHTTPContext): def topic(self): browser = webdriver() browser.get(self.get_url("/")) return browser def should_prompt_the_user_with_a_login_page(self, topic): expect(topic.title).to_include('Django') return BrowserTests @Vows.batch class TDDDjangoApp(DjangoHTTPContext): def get_settings(self): return "tddapp.settings" def topic(self): self.start_server() class OnChrome(onBrowser(webdriver.Chrome)): pass class OnFirefox(onBrowser(webdriver.Firefox)): pass class OnPhantonJS(onBrowser(webdriver.PhantomJS)): pass ``` On my machine this takes about 22 seconds. I could of course create the server inside of each child context but that just seems wasteful. So I would like the ability to pass in the threadcount to the start_server function so I can use the same code but start the server with multiple threads. Then performance will be greatly improved.... roughly 1.8 seconds on my machine. I'll submit a pull request with the change, this issue is to document the purpose of that pull request. Thanks, Jeremy
rafaelcaricio commented 2013-08-19 08:09:23 +00:00 (Migrated from github.com)

Your pull request was already accepted. So, I will close this issue. Thank you for your collaboration. 👍

Your pull request was already accepted. So, I will close this issue. Thank you for your collaboration. :+1:
This repo is archived. You cannot comment on issues.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: archive/django-pyvows#11
No description provided.