Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

It has just been discovered that research causes cancer in rats.


devel / comp.lang.python / Re: Async options for flask app

SubjectAuthor
* Async options for flask appRimu Atkinson
`- Re: Async options for flask appChris Angelico

1
Async options for flask app

<ue80c6$j305$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28425&group=comp.lang.python#28425

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rimuatkinson+usenet@gmail.com (Rimu Atkinson)
Newsgroups: comp.lang.python
Subject: Async options for flask app
Date: Mon, 18 Sep 2023 10:59:15 +1200
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <ue80c6$j305$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 17 Sep 2023 22:59:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e7fd333e24dc281b55c26daf36173b65";
logging-data="625669"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aO7Z5D2GSQvfU5uLEWLYi"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:LFXTMHCN4kOITfy/vsE4CIc6aA4=
Content-Language: en-NZ
 by: Rimu Atkinson - Sun, 17 Sep 2023 22:59 UTC

Hi all,

I'm writing a fediverse server app, similar to kbin https://kbin.pub/en
and lemmy https://join-lemmy.org/. It's like reddit except anyone can
run a server in the same way email works. This architecture involves a
lot of inter-server communication, potentially involving thousands of
different servers.

So, lots of network I/O. Lots of tasks running in parallel to do I/O
with different servers simultaneously. A fair bit of DB access too.

The current fashion is to do this with cooperative multitasking
(async/await/gevent/etc) to avoid the overhead associated with
continually context switching threads and processes. Correct me if I'm
wrong.

How can I do this with Flask? Any async/await tricks? Can I just
configure gunicorn to use gevent worker threads?
https://flask.palletsprojects.com/en/2.3.x/deploying/gunicorn/

Has anyone tried Quart? https://pypi.org/project/quart/

How well does gevent monkey-patch into a Flask app?

A penny for your thoughts

Thanks!

R

Re: Async options for flask app

<mailman.320.1695010687.23016.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28430&group=comp.lang.python#28430

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news-2.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Async options for flask app
Date: Mon, 18 Sep 2023 14:17:52 +1000
Lines: 52
Message-ID: <mailman.320.1695010687.23016.python-list@python.org>
References: <ue80c6$j305$1@dont-email.me>
<CAPTjJmrv9-ag4O2_FGmX0Gi9KeQjoak_8sw+0JnFyr4hHY90=w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de Q3rkTQ2jLnhcdyPWsgnJyALXnyEgCGs1lIKQcGkkf4Yg==
Cancel-Lock: sha1:5IQlM4s6n63Dk3jRRBKoO46+kGs= sha256:LjATNZBH/tm73jGDR0FoGzbojMkT/SthR/nfmwSH/Yk=
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=RDMrFsR7;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url-ip:140.82/16': 0.03;
'(most': 0.05; '3.8': 0.05; '2023': 0.07; 'url-ip:65/8': 0.07;
'wanting': 0.07; 'wrong.': 0.07; 'cc:addr:python-list': 0.09;
'originally': 0.09; 'overhead': 0.09; 'received:mail-
lj1-x22f.google.com': 0.09; 'say:': 0.09; 'then.': 0.09;
'threads': 0.09; 'url-ip:151.101.0.223/32': 0.09; 'url-
ip:151.101.128.223/32': 0.09; 'url-ip:151.101.192.223/32': 0.09;
'url-ip:151.101.64.223/32': 0.09; 'worker': 0.09; 'yes.': 0.09;
'cc:no real name:2**0': 0.14; 'url:github': 0.14; 'that.': 0.15;
'url-ip:140/8': 0.15; '"current': 0.16; '(b)': 0.16; 'app,': 0.16;
'chrisa': 0.16; 'cooperative': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'mentions': 0.16; 'noting':
0.16; 'pool': 0.16; 'processes.': 0.16; 'readme': 0.16;
'ridiculous': 0.16; 'sept': 0.16; 'subject:app': 0.16; 'thread.':
0.16; 'url:project': 0.16; 'url:pypi': 0.16; 'wrote:': 0.16;
'python': 0.16; 'api': 0.17; 'uses': 0.19; 'cc:addr:python.org':
0.20; 'all,': 0.20; "i've": 0.22; 'run': 0.23; 'cc:2**0': 0.25;
'anyone': 0.25; 'tried': 0.26; 'backed': 0.26; 'configure': 0.26;
'flask': 0.26; 'task': 0.26; 'else': 0.27; 'done': 0.28; 'it,':
0.29; 'putting': 0.31; 'context': 0.32; 'gotten': 0.32; 'python-
list': 0.32; "wouldn't": 0.32; 'message-id:@mail.gmail.com': 0.32;
'but': 0.32; "i'm": 0.33; "i'll": 0.33; 'subject:for': 0.33;
'there': 0.33; 'server': 0.33; 'someone': 0.34; 'same': 0.34;
"didn't": 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'definitely': 0.35; 'felt': 0.35;
'url-ip:104.17/16': 0.35; 'yes,': 0.35; 'from:addr:gmail.com':
0.35; 'mon,': 0.36; 'work,': 0.36; 'those': 0.36; "it's": 0.37;
'way': 0.38; 'quite': 0.39; 'use': 0.39; 'still': 0.40; 'exact':
0.40; 'want': 0.40; 'should': 0.40; 'url-ip:104.21/16': 0.61;
'skip:o 10': 0.61; 'techniques': 0.62; 'url-ip:151.101.0/24':
0.62; 'url-ip:151.101.128/24': 0.62; 'url-ip:151.101.192/24':
0.62; 'url-ip:151.101.64/24': 0.62; 'email': 0.63; 'updates':
0.64; 'benefit': 0.65; 'similar': 0.65; 'well': 0.65; 'let': 0.66;
'back': 0.67; 'maximum': 0.67; 'fee.': 0.69; 'depending': 0.70;
"you'll": 0.73; 'significant': 0.78; 'absolutely': 0.84;
'async/await': 0.84; 'postgresql': 0.84; 'switching': 0.84;
'urge': 0.84; 'that:': 0.91; 'url:x': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1695010684; x=1695615484; darn=python.org;
h=cc:to:subject:message-id:date:from:in-reply-to:references
:mime-version:from:to:cc:subject:date:message-id:reply-to;
bh=uCRR4UCAnt+D/4/lN2VIHatJ2UlvfUOMlyWAWyaGHYg=;
b=RDMrFsR7x8YxCU2HfS5UotTZb6ilpMNvMN3FA/aaBgEfsrnp8aC7tGeYP1J+2H9f5v
kDzkWBcx4ah/a/Mgw+vpqfvmkO4zIfE8rhTGDrOxQitmTYmK/eNAvIVlyxZPd96V2FL8
s/ZtJ7xWwRC1nRUyRGwI9bKrsFz4ZIxWPhm5eyjUywPL/W+MMbSuaBsFWudFW4ibmUj+
xxdPY6eeIeRGL/Z34gCqwvh1QQm4bDeWFcrA0V56VFw1ZW+K6a0b56DWPJUm9dGFCKxU
5mcZruv13YOIo1DmB0L/y/zfzkqam64Gtazl/hsePF120WlZHEtl0TQOAv+g6C+z+WSV
Rn7Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1695010684; x=1695615484;
h=cc:to:subject:message-id:date:from:in-reply-to:references
:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=uCRR4UCAnt+D/4/lN2VIHatJ2UlvfUOMlyWAWyaGHYg=;
b=wijHI4CbEORVU2gQSCbav4/tJLZOUF2Y97t0+f0Sz4jn9R0Ya/yS10wXv5voDjh4jI
THSL8n5iN0sSyiLowO4cCJkxYK7NYUIdIiOWhd/CFLXZhJGYDajq7OFvxumGtgXl/sx/
tFLmuJU0VuB1kmH/mvq9ND/FhdmScD3EFT54a3vhl9liwH4oMD0O723HWWhb9doQzDn8
loEfWBw9+lbS1Qi5+naWh1ZHPUvQQaeMBOHBMiUMt7zhuaybf0MR1x1HfwCuluMUcys+
aFoDKrQSeTrMMYBkNLtmZ3TQEiuxLDb0xvWNfRUvrAry33Ty4g6K0D4FdYj0vpuYRlhB
603A==
X-Gm-Message-State: AOJu0Yz6rMO7te2OjWePhzEGBBIu0I0fUEPwNEcP21DDIqGymBlkVyci
E52EMfgHnAiOjgR07L7mc2h9RCVYke73C+P1+hjsTkC3mDc=
X-Google-Smtp-Source: AGHT+IFO9VQEvGJtMmPlXMzpxVmecXI9/kwtpFcYJa0Ur/4HaSLC+cPWVu41mu1wMejNDg++q+qYajQKgVLAD+2F5bY=
X-Received: by 2002:a2e:9cc1:0:b0:2bd:1000:431d with SMTP id
g1-20020a2e9cc1000000b002bd1000431dmr6793602ljj.10.1695010683897; Sun, 17 Sep
2023 21:18:03 -0700 (PDT)
In-Reply-To: <ue80c6$j305$1@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrv9-ag4O2_FGmX0Gi9KeQjoak_8sw+0JnFyr4hHY90=w@mail.gmail.com>
X-Mailman-Original-References: <ue80c6$j305$1@dont-email.me>
 by: Chris Angelico - Mon, 18 Sep 2023 04:17 UTC

On Mon, 18 Sept 2023 at 13:45, Rimu Atkinson via Python-list
<python-list@python.org> wrote:
>
> Hi all,
>
> I'm writing a fediverse server app, similar to kbin https://kbin.pub/en
> and lemmy https://join-lemmy.org/. It's like reddit except anyone can
> run a server in the same way email works.

And the part you didn't say: It's like Reddit but without a ridiculous
API fee. Right? :)

> The current fashion is to do this with cooperative multitasking
> (async/await/gevent/etc) to avoid the overhead associated with
> continually context switching threads and processes. Correct me if I'm
> wrong.

I wouldn't say "current fashion", but yes, there is significant
benefit in putting more than one task onto any given thread. (Most
likely, if you want maximum throughput, you'll end up wanting a
two-level multiplexer, with a pool of processes, each one managing a
pool of tasks.)

> How can I do this with Flask? Any async/await tricks? Can I just
> configure gunicorn to use gevent worker threads?
> https://flask.palletsprojects.com/en/2.3.x/deploying/gunicorn/

It's been a while since I did it, but it definitely does work, yes.

> Has anyone tried Quart? https://pypi.org/project/quart/

Not me, so I'll let someone else answer that.

> How well does gevent monkey-patch into a Flask app?
>

Here's one where I've done that: https://github.com/rosuav/mustardmine

However, it's worth noting that (a) the exact details might differ
depending on precisely what you use - this is backed by PostgreSQL and
also uses websockets; and (b) I originally did this quite a while ago,
and things may have gotten easier since then. All I know is, it works
if I do it this way, and I haven't felt the urge to mess with that
part of it. You may notice that my README mentions issues with Python
3.8 from back when that was new :)

But with all of those caveats: Yes, this absolutely does work, and I
make use of the Mustard Mine on a regular basis. It gets updates
occasionally, not often, but I bump it onto newer Pythons every now
and then, so the techniques it uses should still be valid.

ChrisA


devel / comp.lang.python / Re: Async options for flask app

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor