No video

KotlinConf 2018 - Kotlin Coroutines in Practice by Roman Elizarov

  Рет қаралды 89,236

JetBrains

JetBrains

5 жыл бұрын

Recording brought to you by American Express americanexpres...
Let's see how Kotlin Coroutines are used to solve real-life concurrency and coordination problems. With coroutines we don't have to worry about shared mutable state and synchronization. We can solve the problems we face using a number of communicating coroutines, where each piece of state is confined to a single coroutine.
About the Presenter:
Roman Elizarov is a professional software developer with more than 17 years of experience. He had started his career at Devexperts, where he designed and developed high-performance trading software for leading brokerage firms and market data delivery services that routinely handle millions of events per second. He is an expert in Java and JVM, particularly in real-time data processing, algorithms and performance optimizations for modern architectures. Roman currently works on Kotlin language at JetBrains. Having worked on very large systems compromising many modules written in different languages, he has a dream of a single language that can be used to write all parts of a very large distributed system, to share and reuse data models and algorithms without friction. Kotlin with JVM and JS backends and upcoming native compiler is the ideal candidate to realize this dream. In 2000 Roman had graduated from St. Petersburg ITMO. He now teaches a course on concurrent and distributed programming in ITMO. During his undergraduate study he participated at ACM International Collegiate Programming Contest (ICPC). Since 1997 and until now Roman serves as a Chief Judge of Northeastern European Regional Programming Contest.

Пікірлер: 48
@zhou7yuan
@zhou7yuan 5 жыл бұрын
Coroutines recap [0:41] Coroutines are like light-weight threads [0:46] Quantity -> Quality [1:44] A practical challenge [2:14] suspend fun downloadContent(location: Location): Content References ->(resolve) Locations ->(download) Contents (parallel) [4:12] (What could go wrong?) [4:42] crash! -> leak! Structured concurrency [5:56] suspend, coroutineScope{ launch{ } } launch ->(child) coroutineScope crash -> coroutineScope ->(cancels) launch coroutineScope waits for completion The State [8:04] Download process [8:21] concurrent -> shared mutable state ⚠️ Shared Mutable State -> Share by Communicating [12:47] Synchronization Primitives -> Communication Primitives classes -> coroutines [13:21] Channel [14:37] (channel example) [14:54] fun CoroutineScope.downloader(references: ReceiveChannel) Convention: function 'launch'ed should be declared as CoroutineScope extension [15:34] Coroutine are cheap! But the work they do... [18:01] Limiting concurrency [18:39] Worker pool [19:02] locations: SendChannel fun CoroutineScope.worker(locations: ReceiveChannel) [20:06] [22:24] data class LocContent(val loc:Location, val content: Content) [22:54] Select [24:49] select { references.onReceive {} contents.onReceive {} } Putting it all together [27:49] Patterns everywhere Worker pool Actor Root CoroutineScope [31:20] class SomethingWithLifecycle: CoroutineScope {} suspend vs scope [35:59] suspend: Does something long & waits for it to complete without blocking CoroutineScope: Launches nw coroutines & quickly returns, does not wait for them (convention) Takeaway [38:12] Q&A [39:53]
@bebebewin
@bebebewin 15 күн бұрын
An amazing talk - Roman's presentations are so neatly organized.
@ErsinErtan
@ErsinErtan 5 жыл бұрын
His working through the problem style of presentation is really effective, well presented Roman
@ryszard.grodzicki
@ryszard.grodzicki 3 жыл бұрын
Should we now use Flow instead of Channels in similar examples?
@MrJesterJam
@MrJesterJam 3 жыл бұрын
That's all quite good until you start using it. When you start using the actor function, for example, you see it is marked as obsolete. What's the alternative? No, alternative, just 2-year old lengthy discussion on a github issue.
@Svetylkovo
@Svetylkovo 5 жыл бұрын
I am wondering, why did Roman choose to use channels for this example? Is it just to ensure the "reactivenes" so that when some new reference comes at some of point of time, it gets processed? Because if it was to be processed e.g. on a button click, I think it could be rewritten without channels entirely and without mutable state + it would be like 100x simpler IMO :-). It is difficult for me to resist the feeling, that this particular example is already going far too academic. I can remember cca 8 years ago, I was a lot into Actors in Scala, but when I left college and jumped into real programming world, I think I've never used it since then. So I don't know, maybe I've never written a concurrent application that was complicated enough, or I just feel more comfortable doing synchronization from time to time :-). Anyway I've been watching coroutines for almost a year now and when I saw this channels entangled design, it gave me a headache :-D. I think if somebody, who has never seen coroutines before, will watch this video, he will run as far as he can :-)).
@andybao3210
@andybao3210 5 жыл бұрын
If you are downloading stuff on a button press, you can just fire up a single coroutine to do it. It would be super simple even without coroutines. But coroutines are designed to make high-concurrency applications easy to build so instead they have to show a more complex example (that actually takes advantage of the full power of coroutines). If you are building apps, sure, you don't need worker pools for everything. If you are building a download server however, then this stuff will be very useful.
@Svetylkovo
@Svetylkovo 5 жыл бұрын
Sounds reasonable, thanks for the insight :-).
@methodsignature
@methodsignature 5 жыл бұрын
I believe channels are necessary to avoid "shared mutability + concurrency" issues. They are basically the alternative.
@mark-147
@mark-147 5 жыл бұрын
Excellent talk. Small typo: should be "if (refs == null)" at 26:46
@DicoTheRedstoner
@DicoTheRedstoner 5 жыл бұрын
noticed that too. It changed from an earlier slide.
@andrybak
@andrybak 5 жыл бұрын
It's woud be more noticeable if one used "blink comparator" that astronomers used to use to find stars.
@karthikperiasami
@karthikperiasami 5 жыл бұрын
@@andrybak LOL
@user-de8iu6vw6g
@user-de8iu6vw6g 3 жыл бұрын
yeah, thanks for that comment, stacked at this line for 10 minutes trying to figure out wtf is going on then just skipped
@ErikHuizinga
@ErikHuizinga 5 жыл бұрын
This talk is essential to understanding some important practicalities about coroutines in Kotlin. Love it. I'd like to help improve the closed captions, but they're not open for contribution. It's unfortunate that automatically generated closed captions don't handle words like 'Kotlin' and 'coroutines' very well. CCs are very useful to watch this video at 2x playback rate to more easily follow what's being said. However, with the bad automatic generation, the CCs don't help.
@JetBrainsTV
@JetBrainsTV 5 жыл бұрын
Thank you for your compliment and offer to help improve the closed captions. We have enabled it for this video so your contribution would be welcome and appreciated!
@ErikHuizinga
@ErikHuizinga 5 жыл бұрын
@@JetBrainsTV the CCs are done and ready for review. Please do so, adjust where needed and publish them.
@DanieleSegato
@DanieleSegato 4 жыл бұрын
I believe the downloader code is bugged. won't work if a location has already been downloaded and a new reference come in cause it gets added to the list but it will not receive the content again.
@danielesegato9153
@danielesegato9153 Жыл бұрын
Additionally to the select issue (deadlock) this video contains another issue: the "global" scope should use a SupervisorJob and not a Job. Otherwise any failing children coroutine will close the scope.
@Igor-jj7ex
@Igor-jj7ex 2 жыл бұрын
How much relevant is this video, after all the updates made to Coroutines between 2018 and 2022? Is it still good for learning them, or too many things changed?
@ficklebar
@ficklebar 3 жыл бұрын
New to coroutines, I understand everything so far, but does anyone else find this code to be incredibly _dense_? I.e., it seems like every line is packed with so much meaning, it really boggles the mind! I have to reign in my habit of skimming code to understand, it would seem. Or maybe it’s just because it’s so foreign to me.
@CommanderSteps
@CommanderSteps 3 жыл бұрын
His talks are actually great to learn the basics and also the best practices of using coroutines.
@monacovova
@monacovova 4 жыл бұрын
Article about deadlocks in code sample from this presentation medium.com/@elizarov/deadlocks-in-non-hierarchical-csp-e5910d137cc
@zhenfangZhang
@zhenfangZhang 3 жыл бұрын
I love every talk by Roman
@dmitriystaeglazov3797
@dmitriystaeglazov3797 3 жыл бұрын
It reminded me Akka in some way. Were you inspired by it, Erlang or something else?
@StasBar
@StasBar 5 жыл бұрын
Love this guy presentations
@krellin
@krellin 5 жыл бұрын
Would be great to have this code published to play with...
@MrPatrikNygren
@MrPatrikNygren 5 жыл бұрын
Here is a link to Romans code github.com/elizarov/DeadlocksInCSP/blob/master/src/DownloaderOriginal.kt#L54, but he explains here that there actually is a risk for deadlock in the code he presents medium.com/@elizarov/deadlocks-in-non-hierarchical-csp-e5910d137cc
@Teguder123
@Teguder123 5 жыл бұрын
We miss your old hair style like in KotlinConf 2017
@marekkondracki88
@marekkondracki88 2 жыл бұрын
Is it still actual?
@Masterrunescapeer
@Masterrunescapeer 5 жыл бұрын
Thanks, this is a very nice presentation.
@dharmeshbasapati5039
@dharmeshbasapati5039 2 жыл бұрын
Hi Team JetBrains, I hope you are doing great. I want to clarify one doubt regarding Kotlin Coroutines. How can I delay the execution of the next line or next block of code in my app until the response of my ongoing API comes? Thanks in Advance !!!
@Punarjagran
@Punarjagran 2 жыл бұрын
job.join()
@dharmeshbasapati5039
@dharmeshbasapati5039 2 жыл бұрын
@@Punarjagran Ohh Thanks. Will check that out.
@Ceisluck
@Ceisluck 5 жыл бұрын
He has a certain resemblance with Elon Musk
@robchr
@robchr 3 жыл бұрын
In russia, the quantity of coroutines has a quality of it's own.
@vorname1485
@vorname1485 5 жыл бұрын
2:16 suspend fun
@PaulSebastianM
@PaulSebastianM 5 жыл бұрын
Suspend? Poor choice of keyword imho.
@cfyxyxydzfxtxyc407
@cfyxyxydzfxtxyc407 4 жыл бұрын
It seems like you missed the power of this technology and just try to create some instead
@PaulSebastianM
@PaulSebastianM 5 жыл бұрын
Fan-out? Magic convention. Don't particularly like this.
@krellin
@krellin 5 жыл бұрын
not magic, depends on type of channel you create, want broadcast create broadcast channel
@utsavpopli3951
@utsavpopli3951 3 жыл бұрын
Why kotlin ? No idea Is it simple ? No. Is it syntactically consistent ? No Does it solve any problem ? No Multiplatform ? No (doesn't support ios, you still need to learn swift/objective c++) Kotlin is shame for developers and by developers. It gives you an idea how terrible things can go wrong if not thought through. Worked on Kotlin for 6 months and I gave up. I find assembly more easy than Kotlin. Stick to traditional lang golang/python/java/nodejs etc.
@pitter6282
@pitter6282 2 жыл бұрын
Gtfo then
@Donaldbeebi
@Donaldbeebi 2 жыл бұрын
oh god cringe, get out of my face
@mikolajgrzaslewicz
@mikolajgrzaslewicz Жыл бұрын
Is it syntactically consistent ? No Does it solve any problem ? No Really bold statements. Could you give some examples? I've been using kotlin for ~5 years. I'm using java only when there are strong project reasons to use it instead of kotlin
KotlinConf 2017 - Introduction to Coroutines by Roman Elizarov
45:32
A little girl was shy at her first ballet lesson #shorts
00:35
Fabiosa Animated
Рет қаралды 20 МЛН
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 6 МЛН
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 11 МЛН
Sunglasses Didn't Cover For Me! 🫢
00:12
Polar Reacts
Рет қаралды 5 МЛН
Lifecycles, Coroutines and Scopes | Alejandro Serrano Mena
38:25
Kotlin by JetBrains
Рет қаралды 10 М.
003. Корутины в Kotlin - Роман Елизаров, JetBrains
1:13:34
Yandex for Developers
Рет қаралды 37 М.
STOP Using Classes In JavaScript | Prime Reacts
14:02
ThePrimeTime
Рет қаралды 231 М.
Coroutines and Loom behind the scenes by Roman Elizarov
45:22
Kotlin by JetBrains
Рет қаралды 31 М.
Роман Елизаров - Корутины в Kotlin
59:04
JPoint, Joker и JUG ru
Рет қаралды 63 М.
95% Don't Understand THIS About Coroutines (Main-Safety)
9:38
Philipp Lackner
Рет қаралды 27 М.
A little girl was shy at her first ballet lesson #shorts
00:35
Fabiosa Animated
Рет қаралды 20 МЛН