Slide 1

Slide 1 text

Django 4.1 での Asynchronous Junya Fukuda DjangoCongress JP 2022

Slide 2

Slide 2 text

•෱ా ൏໵ʢJunya Fukudaʣʢ@JunyaFffʣ •גࣜձࣾ೔ຊγεςϜٕݚʢJSLʣॴଐ ௕໺ݝͷձࣾ •WebΤϯδχΞ •GEEKLAB.NAGANO - ίϛϡχςΟεϖʔεӡӦ •ʢ͓͠͝ͱͰʣόϦϡʔϒοΫε •ຊ޷͖ʹѪ͞ΕΔαʔϏεΛ໨ࢦͯ͠ʢݹຊങऔɾൢചʣ •GEEKLAB.NAGANO - ίϛϡχςΟεϖʔεӡӦ

Slide 3

Slide 3 text

Python実践 •2022೥1݄ൃച ٕज़ධ࿦ࣾ •Python 3 ΤϯδχΞೝఆ࣮ફࢼݧ ओڭࡐ •2࡭໨ʹ͓͢͢Ίʂࣙॻతʹ࢖͍ͬͯ͋͛ͯͩ͘͞ʂ • ҎԼͷষΛ୲౰͍ͯ͠·͢ • Chapter2 ίʔσΟϯάن໿ • Chapter5 ܕώϯτ • Chapter19 ฒߦॲཧɼฒྻॲཧ

Slide 4

Slide 4 text

Django 4.1 での ⾮同期

Slide 5

Slide 5 text

Pythonで⾮同期、使っていますか?✋

Slide 6

Slide 6 text

ありがとうございます。

Slide 7

Slide 7 text

ですよね。 なぜ使わないのでしょうか?

Slide 8

Slide 8 text

⾮同期 使 理由 考 •׳ΕͯΔಉظॲཧͰे෼ •IO͕ͳ͍ʢػցֶश΍σʔλ෼ੳ͕த৺ʣʢCPUʹ͕Μ͹ΒͤΔ͜ͱଟ͍ʣ •ඇಉظॲཧͬͯɺ༧ଌͰ͖ͳ͍ಈ͖Λͦ͠͏ •ଞͷݴޠͰॻ͍ͪΌ͏ʢGo΍JS(nodejs/deno..),Rust,C#,SwiftͳͲʣ

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Djangoの⾮同期対応を待ってるのです

Slide 11

Slide 11 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT

Slide 12

Slide 12 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT

Slide 13

Slide 13 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT

Slide 14

Slide 14 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT Note that, at this stage, the underlying database operations remain synchronous

Slide 15

Slide 15 text

Django 4.1 Asynchronous ͜ͷஈ֊Ͱ͸ɺجຊతͳσʔλϕʔεૢ࡞͸ಉظͷ··Ͱ͋Δ͜ͱʹ஫ҙ͍ͯͩ͘͠͞ɻ IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT Note that, at this stage, the underlying database operations remain synchronous

Slide 16

Slide 16 text

🤔

Slide 17

Slide 17 text

🤔 ͳͥɺ03.͸ΠϯλʔϑΣʔε͚ͩରԠͨ͠ΜͩΖ͏ ͍·ɺ%KBOHPͷඇಉظରԠ࣮ͬͯࡍͲ͏ͳ͍ͬͯΔΜͩΖ͏ʜ

Slide 18

Slide 18 text

( 話 ?) •ڈ೥ͷDjangoCongress JP 2021 ͰͷτʔΫΛΞοϓσʔτ͍ͨ͠ •Django 3.2 ASGI ରԠ - ͜Θ͘ͳ͍ asyncio جૅͱ async view ͷ࢖͍ॴ IUUQTMPHNJKQUFDIBSUJDMFT •DjangoͷORM͸ͳͥਖ਼ࣜରԠͰ͸ͳ͍ͷ͔ •΋͔ͨ͠͠Βͦ͏ࢥΘΕͨํ΋͍Βͬ͠ΌΔ͔΋͠Ε·ͤΜʢΘͨ͠

Slide 19

Slide 19 text

本⽇ •Django 4.1 ඇಉظରԠ͕Θ͔ͬͨ •ΫϥεϕʔεϏϡʔ •ORMͷΠϯλʔϑΣʔε •Ωʔϫʔυ͸ •·ͨඇಉظORMΠϯλʔϑΣʔε͸ͳͥ׬શରԠͰ͸ͳ͘ɺಉظͷ··ͳͷ͔ ޓ׵ੑ

Slide 20

Slide 20 text

話 ・話 •DjangoͷViewͷجຊతͳ࢓૊Έ •Djangoͷmodelͷఆٛ •asyncioͷࡉ͔͍͜ͱ •࿩͞ͳ͍͜ͱ •࿩͢͜ͱ •Django 4.1ͷΫϥεϕʔεϏϡʔɾORM

Slide 21

Slide 21 text

•Django 4.1 ඇಉظରԠͱ͍··Ͱͷ͓͞Β͍ •ΫϥεϕʔεϏϡʔͷඇಉظରԠ •؆୯ͳίʔυ ΫϥεϕʔεϏϡʔͷ಺ଆ •ಉظɾඇಉظΫϥεϕʔεϏϡʔͰͷಈ࡞ൺֱ •ඇಉظ ORM ΠϯλʔϑΣʔε •֓ཁ •ಉظɾඇಉظORMͰͷಈ࡞ൺֱ •ඇಉظORM ΠϯλʔϑΣʔεͷ޲͜͏ଆ

Slide 22

Slide 22 text

•Django 4.1 ඇಉظରԠͱ͍··Ͱͷ͓͞Β͍ •ΫϥεϕʔεϏϡʔͷඇಉظରԠ •؆୯ͳίʔυ ΫϥεϕʔεϏϡʔͷ಺ଆ •ಉظɾඇಉظΫϥεϕʔεϏϡʔͰͷಈ࡞ൺֱ •ඇಉظ ORM ΠϯλʔϑΣʔε •֓ཁ •ಉظɾඇಉظORMͰͷಈ࡞ൺֱ •ඇಉظORM ΠϯλʔϑΣʔεͷ޲͜͏ଆ

Slide 23

Slide 23 text

- Django ⾮同期対応 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 24

Slide 24 text

- Django ⾮同期対応 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 25

Slide 25 text

- Django ⾮同期対応 2005 Django OSS •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 26

Slide 26 text

- Django ⾮同期対応 2005 Django OSS 1.0 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 27

Slide 27 text

- Django ⾮同期対応 2005 Django OSS 1.0 1.4 LTS 2012 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 28

Slide 28 text

- Django ⾮同期対応 2005 Django OSS 1.0 1.4 LTS 1.8 LTS 2015 2012 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 29

Slide 29 text

- Django ⾮同期対応 2005 Django OSS 1.0 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2017 2015 2012 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 30

Slide 30 text

- Django ⾮同期対応 2005 Django OSS 1.0 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.0 2019 2017 2015 2012 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 31

Slide 31 text

- Django ⾮同期対応 2005 Django OSS 1.0 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.0 3.2 LTS 4.0 2021 2019 2017 2015 2012 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 32

Slide 32 text

- Django ⾮同期対応 2005 Django OSS 1.0 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.0 3.2 LTS 4.0 4.1 2022 2021 2019 2017 2015 2012 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 33

Slide 33 text

- Django ⾮同期対応 2005 Django OSS 1.0 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.0 3.2 LTS 4.0 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2008 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 34

Slide 34 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 3.0 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2.2 LTS •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 35

Slide 35 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 3.0 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio 2.2 LTS •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 36

Slide 36 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 3.0 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await Python 3.5 2.2 LTS •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 37

Slide 37 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 3.0 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await 2016 Python 3.5 asgiref 1.0 2.2 LTS •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 38

Slide 38 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.0 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await asgiref 1.0 2016 Python 3.5 channels •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 39

Slide 39 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.0 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await asgiref 1.0 2016 Python 3.5 channels asgiref 3.0 •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 40

Slide 40 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await asgiref 1.0 2016 Python 3.5 channels asgiref 3.0 3.0 asgiରԠ •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 41

Slide 41 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await asgiref 1.0 2016 Python 3.5 channels asgiref 3.0 3.0 ؔ਺view asgiରԠ •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 42

Slide 42 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await asgiref 1.0 2016 Python 3.5 channels asgiref 3.0 3.0 asgiରԠ ؔ਺view ΫϥεϏϡʔ ORM IF •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 43

Slide 43 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await asgiref 1.0 2016 Python 3.5 channels asgiref 3.0 3.0 asgiରԠ ؔ਺view ΫϥεϏϡʔ ORM IF •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 44

Slide 44 text

- Django ⾮同期対応 1.4 LTS 1.8 LTS 1.11 LTS 2.0 2.2 LTS 3.2 LTS 4.1 4.2 LTS 2023 2022 2021 2019 2017 2015 2012 2014 Python 3.4 asyncio async/await asgiref 1.0 2016 Python 3.5 channels asgiref 3.0 3.0 asgiରԠ ؔ਺view ΫϥεϏϡʔ ORM IF DEP 0009: Async-capable DjangoʢDEP͸DjangoͷPEPʣ •Έͳ͞Μ͕ॳΊͯ͞ΘͬͨDjangoͷόʔδϣϯ͸͍ͭ͘Ͱ͠ΐ͏͔ʁ

Slide 45

Slide 45 text

- asyncio 基本 •ඇಉظॲཧͷίʔυΛॻͨ͘ΊͷެࣜϥΠϒϥϦ •ෳ਺ͷλεΫΛಉ࣌ʹॲཧ͢Δ •I/Oό΢ϯυͳॲཧʢDBΞΫηε/HTTPϦΫΤετͳͲʣͰޮՌΛൃش •֎෦API-A, ֎෦API-B, ֎෦API-C Λಉ࣌ʹ࣮ߦ͍ͨ͠ •ಉظॲཧͩͱ ॱ൪ʹ࣮ߦ " # $

Slide 46

Slide 46 text

- asyncio 基本 •ඇಉظॲཧͷίʔυΛॻͨ͘ΊͷެࣜϥΠϒϥϦ •ෳ਺ͷλεΫΛಉ࣌ʹॲཧ͢Δ •I/Oό΢ϯυͳॲཧʢDBΞΫηε/HTTPϦΫΤετͳͲʣͰޮՌΛൃش •֎෦API-A, ֎෦API-B, ֎෦API-C Λಉ࣌ʹ࣮ߦ͍ͨ͠ •ඇಉظॲཧͩͱ ·ͱΊͯಉ࣌ʹ࣮ߦ C B A

Slide 47

Slide 47 text

- asyncio 基本 •ඇಉظॲཧͷίʔυΛॻͨ͘Ίͷඪ४ϥΠϒϥϦ •ຖόʔδϣϯਐԽ ߴϨϕϧAPI͕ॆ࣮ - ͱͯ΋ॻ͖΍͍͢ •ෳ਺ͷλεΫΛಉ࣌ʹॲཧ͢Δ •I/Oό΢ϯυͳॲཧʢDBΞΫηε/HTTPϦΫΤετͳͲʣͰޮՌΛൃش •async/await ߏจ •λεΫΛొ࿥͢Δasyncio.create_task() - ʮλεΫʯ = ॲཧͩͱࢥ͍ͬͯͩ͘͞ɻ •ॲཧΛฒߦʹ͢Δasyncio.gather() •ྫ֎΍ΩϟϯηϧΛॊೈʹ asyncio.TaskGroup •αʔυύʔςΟͷϥΠϒϥϦΛ࢖͏৔߹ɺඇಉظରԠ͍ͯ͠Δඞཁ͕͋Δ

Slide 48

Slide 48 text

Django

Slide 49

Slide 49 text

Django 63- σΟεύο νϟʔ 63-DPOG Ϗϡʔ ϑΥʔϜ ςϯϓϨʔτ Ϟσϧ DjangoϓϩδΣΫτ ϒϥ΢β Webαʔό ΞϓϦέʔγϣϯαʔό ϦΫΤ ετ ֎෦Ϧιʔε ϛυϧ ΢ΣΞ Ϩεϙ ϯε

Slide 50

Slide 50 text

Django 63- σΟεύο νϟʔ 63-DPOG Ϗϡʔ ϑΥʔϜ ςϯϓϨʔτ Ϟσϧ DjangoϓϩδΣΫτ ϒϥ΢β Webαʔό ΞϓϦέʔγϣϯαʔό ϦΫΤ ετ ֎෦Ϧιʔε ϛυϧ ΢ΣΞ Ϩεϙ ϯε ʮݱ৔Ͱ࢖͑ΔDjangoͷڭՊॻʯΛࢀߟʹ͍͖ͤͯͨͩ͞·ͨ͠

Slide 51

Slide 51 text

Django 63- σΟεύο νϟʔ 63-DPOG Ϗϡʔ ϑΥʔϜ ςϯϓϨʔτ Ϟσϧ DjangoϓϩδΣΫτ ϒϥ΢β Webαʔό ΞϓϦέʔγϣϯαʔό ϦΫΤ ετ ֎෦Ϧιʔε ϛυϧ ΢ΣΞ Ϩεϙ ϯε ඇಉظରԠ ΫϥεϕʔεϏϡʔ 03.ΠϯλʔϑΣʔε

Slide 52

Slide 52 text

Django 63- σΟεύο νϟʔ 63-DPOG Ϗϡʔ ϑΥʔϜ ςϯϓϨʔτ Ϟσϧ DjangoϓϩδΣΫτ ϒϥ΢β Webαʔό ΞϓϦέʔγϣϯαʔό ϦΫΤ ετ ֎෦Ϧιʔε ϛυϧ ΢ΣΞ Ϩεϙ ϯε ඇಉظରԠ ΫϥεϕʔεϏϡʔ 03.ΠϯλʔϑΣʔε

Slide 53

Slide 53 text

Django 63- σΟεύο νϟʔ 63-DPOG Ϗϡʔ ϑΥʔϜ ςϯϓϨʔτ Ϟσϧ DjangoϓϩδΣΫτ ϒϥ΢β Webαʔό ΞϓϦέʔγϣϯαʔό ϦΫΤ ετ ֎෦Ϧιʔε ϛυϧ ΢ΣΞ Ϩεϙ ϯε ඇಉظରԠ ΫϥεϕʔεϏϡʔ 03.ΠϯλʔϑΣʔε

Slide 54

Slide 54 text

•Django 4.1 ඇಉظରԠͱ͍··Ͱͷ͓͞Β͍ •ΫϥεϕʔεϏϡʔͷඇಉظରԠ •؆୯ͳίʔυ ΫϥεϕʔεϏϡʔͷ಺ଆ •ಉظɾඇಉظΫϥεϕʔεϏϡʔͰͷಈ࡞ൺֱ •ඇಉظ ORM ΠϯλʔϑΣʔε •֓ཁ •ಉظɾඇಉظORMͰͷಈ࡞ൺֱ •ඇಉظORM ΠϯλʔϑΣʔεͷ޲͜͏ଆ

Slide 55

Slide 55 text

⾮同期対応 •viewΫϥεͰίϧʔνϯͷఆ͕ٛՄೳ •django.views.generic.base.view ͢΂ͯͷviewͷ਌Ϋϥε •get, post, put, delete, ͳͲͷϦΫΤετϝιου͕ରԠ •؆୯ͳίʔυΛݟͯΈ·͠ΐ͏

Slide 56

Slide 56 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View views.py

Slide 57

Slide 57 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View views.py

Slide 58

Slide 58 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): views.py

Slide 59

Slide 59 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View class AsyncView(View): async def get(self, request, *args, **kwargs): # Perform view logic using await. await asyncio.sleep(1) return HttpResponse("Hello async world!") views.py

Slide 60

Slide 60 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View async def post(self, request, *args, **kwargs): ... async def put(self, request, *args, **kwargs): ... class AsyncView(View): async def get(self, request, *args, **kwargs): # Perform view logic using await. await asyncio.sleep(1) return HttpResponse("Hello async world!") views.py

Slide 61

Slide 61 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ urlpatterns = [ ] urls.py

Slide 62

Slide 62 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ urlpatterns = [ ] urls.py path('sample/', AsyncView.as_view(), name='sample'),

Slide 63

Slide 63 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ urlpatterns = [ ] urls.py path('sample/', AsyncView.as_view(), name='sample'),

Slide 64

Slide 64 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View async def post(self, request, *args, **kwargs): ... class AsyncView(View): async def get(self, request, *args, **kwargs): # Perform view logic using await. await asyncio.sleep(1) return HttpResponse("Hello async world!") views.py async def put(self, request, *args, **kwargs): ... ఆٛ࣌ͷ஫ҙ఺

Slide 65

Slide 65 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View async def post(self, request, *args, **kwargs): ... class AsyncView(View): async def get(self, request, *args, **kwargs): # Perform view logic using await. await asyncio.sleep(1) return HttpResponse("Hello async world!") views.py async def put(self, request, *args, **kwargs): ... ఆٛ࣌ͷ஫ҙ఺

Slide 66

Slide 66 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View def post(self, request, *args, **kwargs): ... class AsyncView(View): async def get(self, request, *args, **kwargs): # Perform view logic using await. await asyncio.sleep(1) return HttpResponse("Hello async world!") views.py async def put(self, request, *args, **kwargs): ... ఆٛ࣌ͷ஫ҙ఺

Slide 67

Slide 67 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View def post(self, request, *args, **kwargs): ... class AsyncView(View): async def get(self, request, *args, **kwargs): # Perform view logic using await. await asyncio.sleep(1) return HttpResponse("Hello async world!") views.py async def put(self, request, *args, **kwargs): ... ఆٛ࣌ͷ஫ҙ఺ *NQSPQFSMZ$PO fi HVSFE

Slide 68

Slide 68 text

ΫϥεϕʔεϏϡʔͷඇಉظରԠ import asyncio from django.http import HttpResponse from django.views import View async def post(self, request, *args, **kwargs): ... class AsyncView(View): async def get(self, request, *args, **kwargs): # Perform view logic using await. await asyncio.sleep(1) return HttpResponse("Hello async world!") views.py async def put(self, request, *args, **kwargs): ... ఆٛ࣌ͷ஫ҙ఺

Slide 69

Slide 69 text

⾮同期対応 •ίϛοτ͸1ͭ

Slide 70

Slide 70 text

⾮同期対応 •ίϛοτ͸1ͭ •मਖ਼͸ܰඍ υΩϡϝϯτɾςετΛআ͘ͱ30ߦఔ౓ IUUQTHJUIVCDPNEKBOHPEKBOHPQVMM

Slide 71

Slide 71 text

Django/views/generics/base.py class View: ⾮同期対応 @classproperty def view_is_async(cls): handlers = [ getattr(cls, method) for method in cls.http_method_names if (method != "options" and hasattr(cls, method)) ] if not handlers: return False is_async = asyncio.iscoroutinefunction(handlers[0]) if not all(asyncio.iscoroutinefunction(h) == is_async for h in handlers[1:]): raise ImproperlyConfigured( f"{cls.__qualname__} HTTP handlers must either be all sync or all " "async." ) return is_async

Slide 72

Slide 72 text

Django/views/generics/base.py class View: ⾮同期対応 ... if cls.view_is_async: view._is_coroutine = asyncio.coroutines._is_coroutine

Slide 73

Slide 73 text

Django/views/generics/base.py class View: ⾮同期対応 ... if self.view_is_async: async def func(): return response return func() else: return response

Slide 74

Slide 74 text

⾮同期対応 •ίϛοτ͸1ͭ •मਖ਼͸ܰඍ υΩϡϝϯτɾςετΛআ͘ͱ30ߦఔ౓ IUUQTHJUIVCDPNEKBOHPEKBOHPQVMM •asgi.pyͳͲΛؚΊରԠͷ४උ͸੔͍ͬͯͨ

Slide 75

Slide 75 text

同期 ⾮同期 •ΫϥεϕʔεϏϡʔͰ֎෦APIΛ࣮ߦ͢Δྫ •ಉظɾඇಉظͰͦΕͧΕ ׬ྃ·Ͱͷ࣌ؒΛܭଌ •pokemonͷඇެࣜAPIʢओʹֶश޲͚ͷAPI ɺ༻๏༰ྔ͸कͬͯ •viewΫϥεΛར༻͠ɺςϯϓϨʔτͰදࣔ͢Δ •151ඖͷϙέϞϯͷ໊લΛऔಘ

Slide 76

Slide 76 text

同期 ⾮同期 •ಈ࡞؀ڥ - ϩʔΧϧ •MacBook Proʢ14Πϯνɺ2021ʣ •Apple M1 Pro ϝϞϦ32gb

Slide 77

Slide 77 text

同期処理 ⾮同期処理

Slide 78

Slide 78 text

同期処理 ⾮同期処理 requests

Slide 79

Slide 79 text

ΫϥεϕʔεϏϡʔಉظίʔυ class PokeView(View): URL = "https://pokeapi.co/api/v2/pokemon/" def get(self, request, *args, **kwargs): start = time() pokemons = [] for number in range(1, 152): url = f'https://pokeapi.co/api/v2/pokemon/{number}' r = requests.get(url) pokemon = r.json() pokemons.append({"name" : pokemon['name']}) finish = (time() - start) context = {"pokemons": pokemons, "finish_time": finish} return render(request, “sync.html", context) views.py ֎෦APIΛ࣮ߦ

Slide 80

Slide 80 text

urlpatterns = [ path('sync/', PokeView.as_view(), name=‘syncpoke'), ] ΫϥεϕʔεϏϡʔಉظίʔυ urls.py ֎෦APIΛ࣮ߦ

Slide 81

Slide 81 text

ΫϥεϕʔεϏϡʔͷ ಉظίʔυ urls.py

Slide 82

Slide 82 text

ΫϥεϕʔεϏϡʔͷ ಉظίʔυ urls.py

Slide 83

Slide 83 text

ΫϥεϕʔεϏϡʔͷ ಉظίʔυ urls.py

Slide 84

Slide 84 text

同期処理 ⾮同期処理

Slide 85

Slide 85 text

同期処理 ⾮同期処理 httpx

Slide 86

Slide 86 text

同期処理 ⾮同期処理 httpx async対応のサードパーティライブラリ

Slide 87

Slide 87 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ class AsyncPokeView(View): URL = "https://pokeapi.co/api/v2/pokemon/" async def get(self, request, *args, **kwargs): start = time() async with httpx.AsyncClient() as client: tasks = [self.access_url_poke(client, number) for number in range(1, 152)] pokemmons = await asyncio.gather(*tasks, return_exceptions=True) finish = (time() - start) context = {"pokemons": pokemmons, "finish_time": finish} return render(request, "async.html", context) async def access_url_poke(self, client, num: int) -> str: r = await client.get(f"{self.URL}{num}") pokemon = r.json() return {"name": pokemon['name']} views.py ֎෦APIΛ࣮ߦ

Slide 88

Slide 88 text

urlpatterns = [ path('async/', AsyncPokeView.as_view(), name=‘asyncpoke'), ] ΫϥεϕʔεϏϡʔඇಉظίʔυ urls.py ֎෦APIΛ࣮ߦ

Slide 89

Slide 89 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ ࣮ߦ݁Ռ ֎෦APIΛ࣮ߦ

Slide 90

Slide 90 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ ࣮ߦ݁Ռ ֎෦APIΛ࣮ߦ

Slide 91

Slide 91 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ ࣮ߦ݁Ռ ֎෦APIΛ࣮ߦ

Slide 92

Slide 92 text

同期 ⾮同期 •࣮ߦ݁Ռ •ಉظɿ18ඵ •ඇಉظɿ0.7ඵ •ඇಉظͱͯ΋͸΍͍ •APIΛ151ճ΋ୟ͘ඇಉظʹ༗རͳܭଌʢͻ͍͖ •ͦͷଞͷ࢖͍ํ - DjangoCon 2022 •Async Django: The practical guide you've been *awaiting* for by Carlton Gibson •https://www.youtube.com/watch?v=B5uQPwX4VLo •֎෦APIΛಉ࣌ʹ࣮ߦ͢Δ৔߹ʹ࠾༻͠ͳ͍ख͸ͳ͍ •ʮඇಉظDjangoͷ͋ͳ͕ͨ଴ͪ๬ΜͰ͍࣮ͨ༻తͳΨΠυϒοΫʯνϟοτ Channels

Slide 93

Slide 93 text

•Django 4.1 ඇಉظରԠͱ͍··Ͱͷ͓͞Β͍ •ΫϥεϕʔεϏϡʔͷඇಉظରԠ •؆୯ͳίʔυ ΫϥεϕʔεϏϡʔͷ಺ଆ •ಉظɾඇಉظΫϥεϕʔεϏϡʔͰͷಈ࡞ൺֱ •ඇಉظ ORM ΠϯλʔϑΣʔε •֓ཁ •ಉظɾඇಉظORMͰͷಈ࡞ൺֱ •ඇಉظORM ΠϯλʔϑΣʔεͷ޲͜͏ଆ

Slide 94

Slide 94 text

⾮同期 ORM •QuerySetͷϝιουʹ઀಄ࣙʮaʯ͕͍ͭͨඇಉظ൛͕௥Ճ •໋໊نଇ͸3ͭͷީิ 1."_async" pre fi x, 2."_async" suf fi x 3."a" pre fi x _async_get get_async aget ଞʹ΋a.getͳͲ •ٞ࿦ͷ຤ɺPythonͷํ޲ੑ(e.g. __aiter__, __anext__, __aenter__, __aexit__ etc.) •3͕࠾༻ʹ IUUQTGPSVNEKBOHPQSPKFDUDPNUOBNJOHPGBTZODWBSJBOUT

Slide 95

Slide 95 text

⾮同期 ORM •QuerySetͷϝιουʹ઀಄ࣙʮaʯ͕͍ͭͨඇಉظ൛͕௥Ճ •db.models.guery •aiterator, aaggregate, acount, aget, acreate, abulk_create, abulk_update, • aget_or_create, aupdate_or_create, aearliest, alatest, a fi rst, alast, ain_bulk, • aupdate, adelete, aexists, acontains, aexplain •ʢ´-`ʣ.ŇoOʢ໊લ͕ؾʹͳΔ΋ͷ΋͋Δ… acount, aggregate, adelete …ʣ •·ͣ͸؆୯ʹಈ͔ͯ͠Έ·͠ΐ͏

Slide 96

Slide 96 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ $ python manage.py shell Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help. views.py ֎෦APIΛ࣮ߦ

Slide 97

Slide 97 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ $ python manage.py shell Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help. views.py ֎෦APIΛ࣮ߦ In [1]: from django.contrib.auth.models import User

Slide 98

Slide 98 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ $ python manage.py shell Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help. views.py ֎෦APIΛ࣮ߦ In [1]: from django.contrib.auth.models import User In [2]: admin_user = User.objects.get(id=1) In [3]: admin_user Out[3]:

Slide 99

Slide 99 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ $ python manage.py shell Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help. views.py ֎෦APIΛ࣮ߦ In [1]: from django.contrib.auth.models import User In [2]: admin_user = User.objects.get(id=1) In [3]: admin_user Out[3]: In [4]: admin_user = User.objects.aget(id=1)

Slide 100

Slide 100 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ $ python manage.py shell Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help. views.py ֎෦APIΛ࣮ߦ In [1]: from django.contrib.auth.models import User In [2]: admin_user = User.objects.get(id=1) In [3]: admin_user Out[3]: In [4]: admin_user = User.objects.aget(id=1) In [5]: admin_user Out[5]:

Slide 101

Slide 101 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ $ python manage.py shell Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help. views.py ֎෦APIΛ࣮ߦ In [1]: from django.contrib.auth.models import User In [2]: admin_user = User.objects.get(id=1) In [3]: admin_user Out[3]: In [4]: admin_user = User.objects.aget(id=1) In [6]: admin_user = await User.objects.aget(id=1) In [5]: admin_user Out[5]:

Slide 102

Slide 102 text

ΫϥεϕʔεϏϡʔඇಉظίʔυ $ python manage.py shell Python 3.11.0 (v3.11.0:deaf509e8f, Oct 24 2022, 14:43:23) [Clang 13.0.0 (clang-1300.0.29.30)] Type 'copyright', 'credits' or 'license' for more information IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help. views.py ֎෦APIΛ࣮ߦ In [1]: from django.contrib.auth.models import User In [2]: admin_user = User.objects.get(id=1) In [3]: admin_user Out[3]: In [4]: admin_user = User.objects.aget(id=1) In [6]: admin_user = await User.objects.aget(id=1) In [7]: admin_user Out[7]: In [5]: admin_user Out[5]:

Slide 103

Slide 103 text

動作 ⽐較 - ORM •̎छྨͷϞσϧ ͦΕͧΕ100,000݅ొ࿥͢Δ •ಉظɾඇಉظͰͦΕͧΕ •bulk_create/abulk_create Λ࣮ߦ •଎౓ͱ࣮ߦͷྲྀΕΛݟͯΈΔ

Slide 104

Slide 104 text

動作 ⽐較 - ORM •ಈ࡞؀ڥ - ϩʔΧϧ •MacBook Proʢ14Πϯνɺ2021ʣ •Apple M1 Pro ϝϞϦ32gb

Slide 105

Slide 105 text

同期処理 ⾮同期処理

Slide 106

Slide 106 text

ΫϥεϕʔεϏϡʔಉظίʔυ class SyncOrmView(View): def get(self, request, *args, **kwargs): start = time() users = [] for _ in range(100_000): users.append(User(name="Taro")) snippets = [] for _ in range(100_000): snippets.append(Snippet(title="PingPong")) User.objects.bulk_create(users) Snippet.objects.bulk_create(snippets) finish = (time() - start) context = {"finish_time": finish} return render(request, "sync.html", context) views.py ORM

Slide 107

Slide 107 text

urlpatterns = [ path('sync/', SyncOrmView.as_view(), name=‘syncbulk'), ] urls.py ΫϥεϕʔεϏϡʔಉظίʔυ ORM

Slide 108

Slide 108 text

࣮ߦ݁Ռ ΫϥεϕʔεϏϡʔಉظίʔυ ORM

Slide 109

Slide 109 text

同期処理 ⾮同期処理

Slide 110

Slide 110 text

ΫϥεϕʔεϏϡʔಉظίʔυ class AsyncOrmView(View): async def post(self, request, *args, **kwargs): start = time() users = [] for _ in range(100_000): users.append(User(name="Taro")) snippets = [] for _ in range(100_000): snippets.append(Snippet(title="PingPong")) await asyncio.gather( self.check("user", User, users), self.check("snippet", Snippet, snippets) ) finish = (time() - start) context = {"finish_time": finish} return render(request, "async.html", context) async def check(self, name, model, data): print(f"start {name}") await model.objects.abulk_create(data) print(f"end {name}") views.py ORM

Slide 111

Slide 111 text

urlpatterns = [ path('async/', AsyncOrmView.as_view(), name=‘asyncorm’), ] urls.py ΫϥεϕʔεϏϡʔಉظίʔυ ORM

Slide 112

Slide 112 text

࣮ߦ݁Ռ ΫϥεϕʔεϏϡʔಉظίʔυ ORM

Slide 113

Slide 113 text

࣮ߦ݁Ռ ΫϥεϕʔεϏϡʔಉظίʔυ ORM start user start snippets end user end snippets

Slide 114

Slide 114 text

࣮ߦ݁Ռ ΫϥεϕʔεϏϡʔಉظίʔυ ORM start user start snippets end user end snippets

Slide 115

Slide 115 text

同期 ⾮同期 •ಈ࡞ͷൺֱ •ಈ࡞͔Βɺฒߦʹ࣮ߦ͞Ε͍ͯΔ •ಈ࡞ͷൺֱ݁Ռ͸มΘΒͳ͍ •ͪΐͬͱORMͷཪଆͷ࣮૷ΛݟͯΈ·͠ΐ͏ •ಉظɿ 2.6ඵ •ඇಉظɿ 2.6ඵ •౰વͷಈ࡞ - ΠϯλʔϑΣʔεͷΈͷରԠ •ͳͥ͜ͷΑ͏ͳಈ͖ʹͳ͍ͬͯΔͷ͔

Slide 116

Slide 116 text

abulk_create async def abulk_create( self, objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, update_fields=None, unique_fields=None, ): return await sync_to_async(self.bulk_create)( objs=objs, batch_size=batch_size, ignore_conflicts=ignore_conflicts, update_conflicts=update_conflicts, update_fields=update_fields, unique_fields=unique_fields, )

Slide 117

Slide 117 text

abulk_create async def abulk_create( self, objs, batch_size=None, ignore_conflicts=False, update_conflicts=False, update_fields=None, unique_fields=None, ): return await sync_to_async(self.bulk_create)( objs=objs, batch_size=batch_size, ignore_conflicts=ignore_conflicts, update_conflicts=update_conflicts, update_fields=update_fields, unique_fields=unique_fields, )

Slide 118

Slide 118 text

aget async def aget(self, *args, **kwargs): return await sync_to_async(self.get)(*args, **kwargs)

Slide 119

Slide 119 text

aget async def aget(self, *args, **kwargs): return await sync_to_async(self.get)(*args, **kwargs)

Slide 120

Slide 120 text

sync_to_async •ίʔϧόοΫʹࢦఆ͞Εͨಉظؔ਺ʢ͜ͷ৔߹getʣΛඇಉظͬΆ࣮͘ߦͯ͠ฦ͢ async def aget(self, *args, **kwargs): return await sync_to_async(self.get)(*args, **kwargs)

Slide 121

Slide 121 text

sync_to_async •ίʔϧόοΫʹࢦఆ͞Εͨಉظؔ਺ʢ͜ͷ৔߹getʣΛඇಉظͬΆ࣮͘ߦͯ͠ฦ͢ def sync_to_async( func=None, thread_sensitive=True, executor=None, ): if func is None: return lambda f: SyncToAsync( f, thread_sensitive=thread_sensitive, executor=executor, ) return SyncToAsync( func, thread_sensitive=thread_sensitive, executor=executor, ) BTHJSFGTZODQZ

Slide 122

Slide 122 text

SyncToAsync •ThreadPoolExecutorΛར༻͠ɺಉظؔ਺ΛΠϕϯτϧʔϓ಺Ͱ࣮ߦ͢Δ class SyncToAsync: ... async def __call__(self, *args, **kwargs): loop = asyncio.get_running_loop() ... executor = AsyncToSync.loop_thread_executors[loop]

Slide 123

Slide 123 text

SyncToAsync •ThreadPoolExecutorΛར༻͠ɺಉظؔ਺ΛΠϕϯτϧʔϓ಺Ͱ࣮ߦ͢Δ class SyncToAsync: ... async def __call__(self, *args, **kwargs): loop = asyncio.get_running_loop() ... executor = AsyncToSync.loop_thread_executors[loop] future = loop.run_in_executor( executor, functools.partial( self.thread_handler, loop, self.get_current_task(), sys.exc_info(), func, *args, **kwargs, ),

Slide 124

Slide 124 text

SyncToAsync •ThreadPoolExecutorΛར༻͠ɺಉظؔ਺ΛΠϕϯτϧʔϓ಺Ͱ࣮ߦ͢Δ class SyncToAsync: ... async def __call__(self, *args, **kwargs): loop = asyncio.get_running_loop() ... executor = AsyncToSync.loop_thread_executors[loop] future = loop.run_in_executor( executor, functools.partial( self.thread_handler, loop, self.get_current_task(), sys.exc_info(), func, *args, **kwargs, ), Πϕϯτϧʔϓ಺Ͱ&YFDVUPSΛ࢖͏

Slide 125

Slide 125 text

- ORM ⾮同期 •Ͱ͸ͳͥasyncରԠΛORMΠϯλʔϑΣʔε͸ͨ͠ͷ͔

Slide 126

Slide 126 text

- ORM ⾮同期 •Ͱ͸ͳͥasyncରԠΛORMΠϯλʔϑΣʔε͸ͨ͠ͷ͔ •։ൃऀ͸ҙࣝ͢Δ͜ͱͳ͘ɺasync/awaitͰॻ͘͜ͱ͕Ͱ͖Δ •ඇಉظ΁ͷҠߦʹࡍ͠ɺ͋Β͔͡Ίมߋ͓ͯ͘͜͠ͱ͕Ͱ͖Δ

Slide 127

Slide 127 text

- ORM ⾮同期 •Ͱ͸ͳͥasyncରԠΛORMΠϯλʔϑΣʔε͸ͨ͠ͷ͔ •։ൃऀ͸ҙࣝ͢Δ͜ͱͳ͘ɺasync/awaitͰॻ͘͜ͱ͕Ͱ͖Δ •ඇಉظ΁ͷҠߦʹࡍ͠ɺ͋Β͔͡Ίมߋ͓ͯ͘͜͠ͱ͕Ͱ͖Δ •ORMͷͨΊʹɺViewΛඇಉظʹ͠ͳͯ͘΋Α͍ •channels΍֎෦ϦιʔεΛར༻͢Δ৔߹ •ORM͸ඇಉظIFΛར༻͠಺෦ಉظͰಈ࡞ͤ͞Δ

Slide 128

Slide 128 text

- ORM ⾮同期 •Ͱ͸ͳͥasyncରԠΛORMΠϯλʔϑΣʔε͸ͨ͠ͷ͔ •։ൃऀ͸ҙࣝ͢Δ͜ͱͳ͘ɺasync/awaitͰॻ͘͜ͱ͕Ͱ͖Δ •ඇಉظ΁ͷҠߦʹࡍ͠ɺ͋Β͔͡Ίมߋ͓ͯ͘͜͠ͱ͕Ͱ͖Δ •ORMͷͨΊʹɺViewΛඇಉظʹ͠ͳͯ͘΋Α͍ •channels΍֎෦ϦιʔεΛར༻͢Δ৔߹ •ORM͸ඇಉظIFΛར༻͠಺෦ಉظͰಈ࡞ͤ͞Δ

Slide 129

Slide 129 text

DEP 0009: Async-capable Django •ʢDEP͸DjangoͷPEPʣ •Sequencing ͱͯ͠3ஈ֊ IUUQTHJUIVCDPNEKBOHPEFQTCMPCNBJOBDDFQUFEBTZODSTU

Slide 130

Slide 130 text

DEP 0009: Async-capable Django •ʢDEP͸DjangoͷPEPʣ •Sequencing ͱͯ͠3ஈ֊ •First round (hopefully in 3.0) •Further individual projects •Second round (hopefully in 3.1) IUUQTHJUIVCDPNEKBOHPEFQTCMPCNBJOBDDFQUFEBTZODSTU

Slide 131

Slide 131 text

DEP 0009: Async-capable Django •ʢDEP͸DjangoͷPEPʣ •Sequencing ͱͯ͠3ஈ֊ •First round (hopefully in 3.0) •Further individual projects •Second round (hopefully in 3.1) •ORM (async-wrapper interface around existing sync core) •طଘͷಉظίΞʹରԠͨ͠ඇಉظϥούʔΠϯλϑΣʔε •ORM (native async with sync wrappers for backwards compatibility) ޙํޓ׵ੑͷͨΊͷಉظϥούʔΛඋ͑ͨωΠςΟϒඇಉظ IUUQTHJUIVCDPNEKBOHPEFQTCMPCNBJOBDDFQUFEBTZODSTU

Slide 132

Slide 132 text

DEP 0009: Async-capable Django •ʢDEP͸DjangoͷPEPʣ •Sequencing ͱͯ͠3ஈ֊ •First round (hopefully in 3.0) •Further individual projects •Second round (hopefully in 3.1) •ORM (async-wrapper interface around existing sync core) •طଘͷಉظίΞʹରԠͨ͠ඇಉظϥούʔΠϯλϑΣʔε •ORM (native async with sync wrappers for backwards compatibility) ޙํޓ׵ੑͷͨΊͷಉظϥούʔΛඋ͑ͨωΠςΟϒඇಉظ IUUQTHJUIVCDPNEKBOHPEFQTCMPCNBJOBDDFQUFEBTZODSTU ࣮૷ॱং͸༧ఆͲ͓Γʂ

Slide 133

Slide 133 text

4.1 ORM 🤔 •Θͨ͠ͷߟ͑Δཧ༝͸3ͭ

Slide 134

Slide 134 text

4.1 ORM 🤔 •Θͨ͠ͷߟ͑Δཧ༝͸3ͭ •ޓ׵ੑ •ޓ׵ੑΛҡ࣋͢Δํ๏Ͱ࣮૷ΛਐΊ͍ͯΔ •IF͔ΒରԠ͢Δͷ͸౰ॳͷ༧ఆͲ͓Γ •DEP͸ͦΕ΄Ͳ֬ݻͨΔ࢓༷Ͱ͸ͳͦ͞͏ʢ໋໊نଇ΋มߋʹͳͬͯΔ

Slide 135

Slide 135 text

4.1 ORM 🤔 •Θͨ͠ͷߟ͑Δཧ༝͸3ͭ •ޓ׵ੑ •ޓ׵ੑΛҡ࣋͢Δํ๏Ͱ࣮૷ΛਐΊ͍ͯΔ •IF͔ΒରԠ͢Δͷ͸౰ॳͷ༧ఆͲ͓Γ •ඇಉظରԠͷϝΠϯ։ൃऀͷϦιʔεෆ଍ •DEP͸ͦΕ΄Ͳ֬ݻͨΔ࢓༷Ͱ͸ͳͦ͞͏ʢ໋໊نଇ΋มߋʹͳͬͯΔ

Slide 136

Slide 136 text

4.1 ORM 🤔 •Θͨ͠ͷߟ͑Δཧ༝͸3ͭ •ޓ׵ੑ •ޓ׵ੑΛҡ࣋͢Δํ๏Ͱ࣮૷ΛਐΊ͍ͯΔ •ʢ૝૾ʣࢿۚ΋Өڹ͕͋Δͷ͔ʁ •IF͔ΒରԠ͢Δͷ͸౰ॳͷ༧ఆͲ͓Γ •ඇಉظରԠͷϝΠϯ։ൃऀͷϦιʔεෆ଍ •DEP 9 / asgiref ͷ Andrew Godwin ࢯ •DEP͸ͦΕ΄Ͳ֬ݻͨΔ࢓༷Ͱ͸ͳͦ͞͏ʢ໋໊نଇ΋มߋʹͳͬͯΔ

Slide 137

Slide 137 text

4.1 ORM 🤔 •Θͨ͠ͷߟ͑Δཧ༝͸3ͭ •ޓ׵ੑ •ޓ׵ੑΛҡ࣋͢Δํ๏Ͱ࣮૷ΛਐΊ͍ͯΔ •ʢ૝૾ʣࢿۚ΋Өڹ͕͋Δͷ͔ʁ •IF͔ΒରԠ͢Δͷ͸౰ॳͷ༧ఆͲ͓Γ •ඇಉظରԠͷϝΠϯ։ൃऀͷϦιʔεෆ଍ 🤔 •DEP 9 / asgiref ͷ Andrew Godwin ࢯ •PyConJP 2022ͷΩʔϊʔτͷ࿩ʢFaster C Pythonʣ💰 •DEP͸ͦΕ΄Ͳ֬ݻͨΔ࢓༷Ͱ͸ͳͦ͞͏ʢ໋໊نଇ΋มߋʹͳͬͯΔ •DEP 9 Ͱ͸ࢿۚௐୡͷ࿩΋ग़͍ͯΔ Donationͷϖʔδ΋

Slide 138

Slide 138 text

わたしたちにできること

Slide 139

Slide 139 text

わたしたちにできること 開発者の

Slide 140

Slide 140 text

わたしたちにできること (経営者の⽅は… 🙏 開発者の

Slide 141

Slide 141 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT /PUFUIBU BUUIJTTUBHF UIFVOEFSMZJOHEBUBCBTFPQFSBUJPOTSFNBJOTZODISPOPVT ͜ͷஈ֊Ͱ͸ɺجຊతͳσʔλϕʔεૢ࡞͸ಉظͷ··Ͱ͋Δ͜ͱʹ஫ҙ͍ͯͩ͘͠͞ɻ

Slide 142

Slide 142 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT /PUFUIBU BUUIJTTUBHF UIFVOEFSMZJOHEBUBCBTFPQFSBUJPOTSFNBJOTZODISPOPVT ͜ͷஈ֊Ͱ͸ɺجຊతͳσʔλϕʔεૢ࡞͸ಉظͷ··Ͱ͋Γɺ

Slide 143

Slide 143 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT /PUFUIBU BUUIJTTUBHF UIFVOEFSMZJOHEBUBCBTFPQFSBUJPOTSFNBJOTZODISPOPVT XJUIDPOUSJCVUJPOTPOHPJOHUPQVTIBTZODISPOPVTTVQQPSU ͜ͷஈ֊Ͱ͸ɺجຊతͳσʔλϕʔεૢ࡞͸ಉظͷ··Ͱ͋Γɺ

Slide 144

Slide 144 text

Django 4.1 Asynchronous IUUQTEPDTEKBOHPQSPKFDUDPNFOSFMFBTFT /PUFUIBU BUUIJTTUBHF UIFVOEFSMZJOHEBUBCBTFPQFSBUJPOTSFNBJOTZODISPOPVT XJUIDPOUSJCVUJPOTPOHPJOHUPQVTIBTZODISPOPVTTVQQPSU ͜ͷஈ֊Ͱ͸ɺجຊతͳσʔλϕʔεૢ࡞͸ಉظͷ··Ͱ͋Γɺ ඇಉظͷαϙʔτΛਪਐ͢ΔͨΊͷߩݙ͕ଓ͍͍ͯ·͢ɻ

Slide 145

Slide 145 text

•Django͸OSS

Slide 146

Slide 146 text

•Django͸OSS •ඇಉظORMରԠʹ޲͚ͯɺߩݙ͕ߦΘΕ͍ͯΔ

Slide 147

Slide 147 text

•Django͸OSS •ඇಉظORMରԠʹ޲͚ͯɺߩݙ͕ߦΘΕ͍ͯΔ

Slide 148

Slide 148 text

•Django͸OSS •ඇಉظORMରԠʹ޲͚ͯɺߩݙ͕ߦΘΕ͍ͯΔ

Slide 149

Slide 149 text

•Django͸OSS •ඇಉظORMରԠʹ޲͚ͯɺߩݙ͕ߦΘΕ͍ͯΔ •IFͷΈͷରԠͰ͋Δࠓ͸ɺ೉қ౓΋ߴ͘ͳ͘ߩݙ͠΍͍͔͢΋

Slide 150

Slide 150 text

謝辞 •Asynchronous ORM •https://forum.djangoproject.com/t/asynchronous-orm/5925/21 •ݱ৔Ͱ࢖͑Δ Django ͷڭՊॻ - ԣ੉ ໌ਔ(ஶ) •https://akiyoko.booth.pm/items/1059917 •࣮ફDjango PythonʹΑΔຊ֨WebΞϓϦέʔγϣϯ։ൃ - ࣳా ক (ஶ) •https://www.shoeisha.co.jp/book/detail/9784798153964 • Async Django: The practical guide you've been *awaiting* for by Carlton Gibson - DjangoCon Europe 2022 •https://www.youtube.com/watch?v=Lfe2zsGS0Js • Keynote: State of the Object-Relational Mapping (ORM) - Simon Charette •https://2022.djangocon.us/talks/keynote-state-of-orm/

Slide 151

Slide 151 text

ご静聴ありがとうございました 👋