| | 5 | |
| | 6 | |
| | 7 | ---- |
| | 8 | |
| | 9 | **EDIT: I made some basic profiling using `cProfile` for 1000 users using an SQLite database.** |
| | 10 | |
| | 11 | 1. **Current**: 94770 function calls (94752 primitive calls) in 251.144 seconds. [https://gist.github.com/roelzkie15/13cb9c0583f0e57e829067cd5dd1dfeb See all logs]. |
| | 12 | 2. **With sync_to_async**: 407770 function calls (405752 primitive calls) in 251.129 seconds. [https://gist.github.com/roelzkie15/52dd618960b0c1c0da5f1434dea83145 See all logs]. |
| | 13 | 3. **With ThreadPoolExecutor(4)**: 390842 function calls (389818 primitive calls) in 254.972 seconds for 1000 users. [https://gist.github.com/roelzkie15/07bed634a3b0b8acf4fec740d062e7f8 See all logs]. |
| | 14 | 4. **With ThreadPoolExecutor(8)**: 390842 function calls (389818 primitive calls) in 251.255 seconds for 1000 users. [https://gist.github.com/roelzkie15/a227700c1abe29e752f52ce95ee2d951 See all logs]. |
| | 15 | 5. **With ThreadPoolExecutor(12)**: 390842 function calls (389818 primitive calls) in 254.198 seconds for 1000 users. [https://gist.github.com/roelzkie15/a0d69aa3f5f3787e5cf595382ea169e6 See all logs]. |
| | 16 | 6. **ThreadPoolExecutor(16)**: 390842 function calls (389818 primitive calls) in 254.155 seconds for 1000 users. [https://gist.github.com/roelzkie15/a31768102030ad0e532cd5335b8662a1 See all logs]. |
| | 17 | |
| | 18 | They're almost has no difference, but I'm not 100% sure if I'm doing it correctly. Below is the python script for profiling: |
| | 19 | |
| | 20 | |
| | 21 | {{{#!python |
| | 22 | |
| | 23 | import os |
| | 24 | |
| | 25 | import django |
| | 26 | |
| | 27 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") |
| | 28 | django.setup() |
| | 29 | |
| | 30 | # -- |
| | 31 | import asyncio |
| | 32 | import cProfile |
| | 33 | |
| | 34 | from django.contrib.auth.models import User |
| | 35 | |
| | 36 | |
| | 37 | async def main(): |
| | 38 | |
| | 39 | profiler = cProfile.Profile() |
| | 40 | profiler.enable() |
| | 41 | |
| | 42 | async for user in User.objects.all()[:1000]: |
| | 43 | await user.acheck_password(user.username), user.username |
| | 44 | |
| | 45 | profiler.disable() |
| | 46 | profiler.print_stats(sort='cumulative') |
| | 47 | |
| | 48 | |
| | 49 | if __name__ == "__main__": |
| | 50 | asyncio.run(main()) |
| | 51 | |
| | 52 | }}} |
| | 53 | |
| | 54 | System information: |
| | 55 | |
| | 56 | |
| | 57 | {{{#!shell |
| | 58 | $ sysctl -a | grep machdep.cpu |
| | 59 | machdep.cpu.cores_per_package: 8 |
| | 60 | machdep.cpu.core_count: 8 |
| | 61 | machdep.cpu.logical_per_package: 8 |
| | 62 | machdep.cpu.thread_count: 8 |
| | 63 | machdep.cpu.brand_string: Apple M1 |
| | 64 | |
| | 65 | $ python --version |
| | 66 | Python 3.13.2 |
| | 67 | |
| | 68 | $ python -c "import django; print(django.get_version());" |
| | 69 | 5.2.3 |
| | 70 | }}} |
| | 71 | |