public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin][RM5017] Use cheroot as default production server
6+ messages / 3 participants
[nested] [flat]

* [pgAdmin][RM5017] Use cheroot as default production server
@ 2019-12-17 09:45  Aditya Toshniwal <[email protected]>
  0 siblings, 2 replies; 6+ messages in thread

From: Aditya Toshniwal @ 2019-12-17 09:45 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

Attached is the patch to use https://pypi.org/project/cheroot/ instead of
current flask dev server. cheroot is a stable production ready server.
Plus, flask dev server is not recommended for production.
Code is changed to use cheroot only when DEBUG is False, otherwise you the
default flask server.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Sr. Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"


Attachments:

  [application/octet-stream] RM5017.patch (2.1K, 3-RM5017.patch)
  download | inline diff:
diff --git a/requirements.txt b/requirements.txt
index dae5436d6..b2e00d610 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -15,6 +15,7 @@
 #       ignored when building a PIP Wheel.
 ##############################################################################
 blinker==1.4
+cheroot==8.2.1
 Flask==1.0.2
 Werkzeug>=0.15.0
 Flask-Gravatar==0.5.0
diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py
index 71eaed5e1..5cfd61253 100644
--- a/web/pgAdmin4.py
+++ b/web/pgAdmin4.py
@@ -13,6 +13,7 @@ to start a web server."""
 
 import os
 import sys
+from cheroot.wsgi import Server as CherootServer
 
 if sys.version_info[0] >= 3:
     import builtins
@@ -190,15 +191,29 @@ if __name__ == '__main__':
     # Reference:
     # https://github.com/pallets/werkzeug/issues/220#issuecomment-11176538
     try:
-        app.run(
-            host=config.DEFAULT_SERVER,
-            port=server_port,
-            use_reloader=(
-                (not PGADMIN_RUNTIME) and app.debug and
-                os.environ.get("WERKZEUG_RUN_MAIN") is not None
-            ),
-            threaded=config.THREADED_MODE
-        )
-
+        if config.DEBUG:
+            app.run(
+                host=config.DEFAULT_SERVER,
+                port=server_port,
+                use_reloader=(
+                    (not PGADMIN_RUNTIME) and app.debug and
+                    os.environ.get("WERKZEUG_RUN_MAIN") is not None
+                ),
+                threaded=config.THREADED_MODE
+            )
+        else:
+            # Can use cheroot instead of flask dev server when not in debug
+            # 10 is default thread count in CherootServer
+            num_threads = 10 if config.THREADED_MODE else 1
+            prod_server = CherootServer(
+                (config.DEFAULT_SERVER, server_port),
+                wsgi_app=app,
+                numthreads=num_threads,
+                server_name=config.APP_NAME)
+            try:
+                print("Using production server...")
+                prod_server.start()
+            except KeyboardInterrupt:
+                prod_server.stop()
     except IOError:
         app.logger.error("Error starting the app server: %s", sys.exc_info())


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM5017] Use cheroot as default production server
@ 2019-12-20 06:04  Akshay Joshi <[email protected]>
  parent: Aditya Toshniwal <[email protected]>
  1 sibling, 0 replies; 6+ messages in thread

From: Akshay Joshi @ 2019-12-20 06:04 UTC (permalink / raw)
  To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Tue, Dec 17, 2019 at 3:16 PM Aditya Toshniwal <
[email protected]> wrote:

> Hi Hackers,
>
> Attached is the patch to use https://pypi.org/project/cheroot/ instead of
> current flask dev server. cheroot is a stable production ready server.
> Plus, flask dev server is not recommended for production.
> Code is changed to use cheroot only when DEBUG is False, otherwise you the
> default flask server.
>
> Kindly review.
>
> --
> Thanks and Regards,
> Aditya Toshniwal
> Sr. Software Engineer | EnterpriseDB India | Pune
> "Don't Complain about Heat, Plant a TREE"
>


-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM5017] Use cheroot as default production server
@ 2019-12-20 08:04  Ashesh Vashi <[email protected]>
  parent: Aditya Toshniwal <[email protected]>
  1 sibling, 1 reply; 6+ messages in thread

From: Ashesh Vashi @ 2019-12-20 08:04 UTC (permalink / raw)
  To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers

Have you seen any improvements in performance?

On Tue, 17 Dec 2019, 15:16 Aditya Toshniwal, <
[email protected]> wrote:

> Hi Hackers,
>
> Attached is the patch to use https://pypi.org/project/cheroot/ instead of
> current flask dev server. cheroot is a stable production ready server.
> Plus, flask dev server is not recommended for production.
> Code is changed to use cheroot only when DEBUG is False, otherwise you the
> default flask server.
>
> Kindly review.
>
> --
> Thanks and Regards,
> Aditya Toshniwal
> Sr. Software Engineer | EnterpriseDB India | Pune
> "Don't Complain about Heat, Plant a TREE"
>


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM5017] Use cheroot as default production server
@ 2019-12-20 12:51  Aditya Toshniwal <[email protected]>
  parent: Ashesh Vashi <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Aditya Toshniwal @ 2019-12-20 12:51 UTC (permalink / raw)
  To: Ashesh Vashi <[email protected]>; +Cc: pgadmin-hackers

Hi Ashesh,

I had tried with - https://newrelic.com/ API to check Flask app
performance. To be honest, there was not a great difference in the
performance.
Per new relic, cheroot used slightly less CPU, with more RPM and, with less
response time.
Anyway, flask is still not recommended and cheroot looks a good option as
it is pure python and supports almost all OS.

On Fri, Dec 20, 2019 at 1:34 PM Ashesh Vashi <[email protected]>
wrote:

> Have you seen any improvements in performance?
>
> On Tue, 17 Dec 2019, 15:16 Aditya Toshniwal, <
> [email protected]> wrote:
>
>> Hi Hackers,
>>
>> Attached is the patch to use https://pypi.org/project/cheroot/ instead
>> of current flask dev server. cheroot is a stable production ready server.
>> Plus, flask dev server is not recommended for production.
>> Code is changed to use cheroot only when DEBUG is False, otherwise you
>> the default flask server.
>>
>> Kindly review.
>>
>> --
>> Thanks and Regards,
>> Aditya Toshniwal
>> Sr. Software Engineer | EnterpriseDB India | Pune
>> "Don't Complain about Heat, Plant a TREE"
>>
>

-- 
Thanks and Regards,
Aditya Toshniwal
pgAdmin Hacker | Sr. Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM5017] Use cheroot as default production server
@ 2019-12-24 07:19  Aditya Toshniwal <[email protected]>
  parent: Aditya Toshniwal <[email protected]>
  0 siblings, 1 reply; 6+ messages in thread

From: Aditya Toshniwal @ 2019-12-24 07:19 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

One of the dependencies of cheroot - jaraco.functools was released on 20th
Dec (v 3.0.0) which removed the support below Python 3.6. So while
installing cheroot (using pgAdmin wheel) on Python 3.5, it is failing.
cheroot works fine with its previous version of jaraco.functools==2.0.0.
I've raised the issue to cheroot -
https://github.com/cherrypy/cheroot/issues/258.
Please note, installers work fine as they are shipped with Python 3.7 venv.
Ref - https://www.postgresql.org/ftp/pgadmin/pgadmin4/snapshots/2019-12-24/
Attached is the patch to pin jaraco.functools to 2.0.0 in requirements so
that it does not fail below Python 3.6.

On Fri, Dec 20, 2019 at 6:21 PM Aditya Toshniwal <
[email protected]> wrote:

> Hi Ashesh,
>
> I had tried with - https://newrelic.com/ API to check Flask app
> performance. To be honest, there was not a great difference in the
> performance.
> Per new relic, cheroot used slightly less CPU, with more RPM and, with
> less response time.
> Anyway, flask is still not recommended and cheroot looks a good option as
> it is pure python and supports almost all OS.
>
> On Fri, Dec 20, 2019 at 1:34 PM Ashesh Vashi <
> [email protected]> wrote:
>
>> Have you seen any improvements in performance?
>>
>> On Tue, 17 Dec 2019, 15:16 Aditya Toshniwal, <
>> [email protected]> wrote:
>>
>>> Hi Hackers,
>>>
>>> Attached is the patch to use https://pypi.org/project/cheroot/ instead
>>> of current flask dev server. cheroot is a stable production ready server.
>>> Plus, flask dev server is not recommended for production.
>>> Code is changed to use cheroot only when DEBUG is False, otherwise you
>>> the default flask server.
>>>
>>> Kindly review.
>>>
>>> --
>>> Thanks and Regards,
>>> Aditya Toshniwal
>>> Sr. Software Engineer | EnterpriseDB India | Pune
>>> "Don't Complain about Heat, Plant a TREE"
>>>
>>
>
> --
> Thanks and Regards,
> Aditya Toshniwal
> pgAdmin Hacker | Sr. Software Engineer | EnterpriseDB India | Pune
> "Don't Complain about Heat, Plant a TREE"
>


-- 
Thanks and Regards,
Aditya Toshniwal
pgAdmin Hacker | Sr. Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"


Attachments:

  [application/octet-stream] RM5017.part2.patch (358B, 3-RM5017.part2.patch)
  download | inline diff:
diff --git a/requirements.txt b/requirements.txt
index b2e00d610..5485652c3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -15,6 +15,7 @@
 #       ignored when building a PIP Wheel.
 ##############################################################################
 blinker==1.4
+jaraco.functools==2.0.0
 cheroot==8.2.1
 Flask==1.0.2
 Werkzeug>=0.15.0


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [pgAdmin][RM5017] Use cheroot as default production server
@ 2019-12-27 06:13  Aditya Toshniwal <[email protected]>
  parent: Aditya Toshniwal <[email protected]>
  0 siblings, 0 replies; 6+ messages in thread

From: Aditya Toshniwal @ 2019-12-27 06:13 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

Turned out my pip was of older version. Upgrading pip solved the
jaraco.functools problem. pip downloaded the suitable version
automatically. Kindly ignore the previous patch.

On Tue, Dec 24, 2019 at 12:49 PM Aditya Toshniwal <
[email protected]> wrote:

> Hi Hackers,
>
> One of the dependencies of cheroot - jaraco.functools was released on
> 20th Dec (v 3.0.0) which removed the support below Python 3.6. So while
> installing cheroot (using pgAdmin wheel) on Python 3.5, it is failing.
> cheroot works fine with its previous version of jaraco.functools==2.0.0.
> I've raised the issue to cheroot -
> https://github.com/cherrypy/cheroot/issues/258.
> Please note, installers work fine as they are shipped with Python 3.7
> venv. Ref -
> https://www.postgresql.org/ftp/pgadmin/pgadmin4/snapshots/2019-12-24/
> Attached is the patch to pin jaraco.functools to 2.0.0 in requirements so
> that it does not fail below Python 3.6.
>
> On Fri, Dec 20, 2019 at 6:21 PM Aditya Toshniwal <
> [email protected]> wrote:
>
>> Hi Ashesh,
>>
>> I had tried with - https://newrelic.com/ API to check Flask app
>> performance. To be honest, there was not a great difference in the
>> performance.
>> Per new relic, cheroot used slightly less CPU, with more RPM and, with
>> less response time.
>> Anyway, flask is still not recommended and cheroot looks a good option as
>> it is pure python and supports almost all OS.
>>
>> On Fri, Dec 20, 2019 at 1:34 PM Ashesh Vashi <
>> [email protected]> wrote:
>>
>>> Have you seen any improvements in performance?
>>>
>>> On Tue, 17 Dec 2019, 15:16 Aditya Toshniwal, <
>>> [email protected]> wrote:
>>>
>>>> Hi Hackers,
>>>>
>>>> Attached is the patch to use https://pypi.org/project/cheroot/ instead
>>>> of current flask dev server. cheroot is a stable production ready server.
>>>> Plus, flask dev server is not recommended for production.
>>>> Code is changed to use cheroot only when DEBUG is False, otherwise you
>>>> the default flask server.
>>>>
>>>> Kindly review.
>>>>
>>>> --
>>>> Thanks and Regards,
>>>> Aditya Toshniwal
>>>> Sr. Software Engineer | EnterpriseDB India | Pune
>>>> "Don't Complain about Heat, Plant a TREE"
>>>>
>>>
>>
>> --
>> Thanks and Regards,
>> Aditya Toshniwal
>> pgAdmin Hacker | Sr. Software Engineer | EnterpriseDB India | Pune
>> "Don't Complain about Heat, Plant a TREE"
>>
>
>
> --
> Thanks and Regards,
> Aditya Toshniwal
> pgAdmin Hacker | Sr. Software Engineer | EnterpriseDB India | Pune
> "Don't Complain about Heat, Plant a TREE"
>


-- 
Thanks and Regards,
Aditya Toshniwal
pgAdmin Hacker | Sr. Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"


^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2019-12-27 06:13 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17 09:45 [pgAdmin][RM5017] Use cheroot as default production server Aditya Toshniwal <[email protected]>
2019-12-20 06:04 ` Akshay Joshi <[email protected]>
2019-12-20 08:04 ` Ashesh Vashi <[email protected]>
2019-12-20 12:51   ` Aditya Toshniwal <[email protected]>
2019-12-24 07:19     ` Aditya Toshniwal <[email protected]>
2019-12-27 06:13       ` Aditya Toshniwal <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox