 Okay, so it's, can you speak? What? Try speaking, yeah. Try speaking something. Yeah. Hello? Works? Okay. Hello, everyone. Thank you for coming to my presentation about the EGLE framework. Today we're going to talk about how to build high performance applications in i2.net core. And I hope I will show you that this framework is not evil anymore. It's quite good for building majority of applications nowadays. First, let me introduce myself. My name is Xavier Bitsky. And I'm working for finance and e-commerce industry for the last 15 years. Currently, I'm co-founder of a company called Web Storting SRO with a headquarter in Rock, Czech Republic. And I'm using .net since version 2002. And for the last few years, I'm super happy about what Microsoft is doing when they start offering sort of things and they start contributing to this community. And I believe that modern .net is a great, great future. And I hope I'll show you. And you'll try to check it and do something. Okay, so first let's talk about what modern .net is. Because currently we have several implementations of .net. The classical one is the .net framework that is .net, you know, for the last 10, 15 years. And it's used for building classical Windows applications like WPF, Windows Forms, like building console tools, and the classical as well as .net, as you know, like web forms, for example. There is new .net that is .net core that is a cross-platform framework that is used mostly for building console applications, I speak of .net core applications that you can run on any environment. And also UWP and Xamarin Forms apps that you can run on mobile or on latest Windows, like Windows 10. And hopefully they will be scalable so you can run the same app on a tablet or a mobile phone or a normal desktop computer. And there's also Xamarin, and Xamarin is a new version of Mono. So the guys who built Mono, they started a campaign and their goal was to bring .net into mobile world. So with Xamarin you can build iOS and Android apps and also Mac OS apps. And they all run natively and smoothly and have like a native platform, CUI. There is a common business understanding between .net core and .net standard. So recently Microsoft introduced .net standard and that's actually a specification. And if you are trying to build your own .net implementation, you have to follow the specification. And the goal is to introduce code reuse and the way like if you build your library for .net standard and it runs on classical .net, you can take the same library, bring it to .net core and run natively on Linux and it will just all work smoothly. And the current version is version two and if you take a look to all open source libraries available on Nougat, Microsoft claims that around 70% of libraries right now are compatible with .net standard. It means you can use almost like two sort of all global libraries available in the world. And there is also a compatibility mode for .net standard two. It means that even if your Nougat package doesn't claim that OKIM supporting .net standard, you can still try to install it and use and your .net core will check and run time if the API supports for you or not and if all your API calls are supported, it will just work out of the box. So .net core, .net core, the current version is version two, technical issues. Okay, so .net core, current version is version two and it's fully cross-platform works on Windows Linux and Mac and it's licensed by MIT license so you can just do whatever you want with it. It supports flexible deployments like you can run them, talk to and deploy to Azure or the AWS smoothly. And of course, as it is .net, you can use any programming that you like. And yeah, it's not about just visual studio nowadays. So you can use any editor like Atom, visual studio code, classical visual studio. There's visual studio for Mac or there's Ryder ID from JetBrains. It's like, there's not a graph. It's like intelligent ID, but that's what we show. So you can do whatever you like, how you want. So now let's move on and start talking about like performance issues and see how you can kind of scale your app or how you can fix performance things. So first let's introduce some little bit of philosophy that I'm following when my client has a problem with performance. So first of all, when you're building a project, you're not Google, because what I've seen a lot when people starting a new app startup, they think, okay, yeah, I'm going to scale for millions of users. That's great if you can do that. But if you want to scale for millions of users, it will be really tough to build it properly. So just start small, build something and evolve as you need. Always think about return of investment. Again, you're not Google and as a startup or a small e-commerce company, you can always invest like a ton of cash just to be like super huge scalable. So just build a minimum value product, bring it to the market and see how it evolves. Yeah, don't reinvent the wheel. That's another problem in our industry. To be honest, I've seen probably 20 or 30 different login frameworks in my career. But there are some that are available and are not for service. And solve your problem first. Again, when you're building a project, I think this is one of the root of performance issues. So when you're building a project, just I think, okay, I want to have a super scalable and I have a nice architecture. And tomorrow I can move from SQL server to MySQL, for example. Usually this never happened. Once you start with a database, it's really hard to change it in the future. So solve your problem and then use the tools that are right for your project. And performance problems are great because usually it means that your project is getting popular and I love performance problems myself. Okay, so let's see if you look. Imagine you have a nice call from a client and saying, hey, my site is super slow. We cannot sell anything. What's going on? The first thing that you can do is just a quick check. Just go to Google page speed. It's a SaaS service where you just type your URL and it'll show you potential performance issues and do some measurements for you. Check your number. And if it's an enterprise app and you don't have a public API, there's two called iSlow. But it does the same checks like Google page speed. And it's also open source nowadays. You can download it from iSlow.org. Just install it. It's a plugin for a browser and run for a website and it'll show you some recommendations and also do some training. Another tool is like, okay, once you see accounts, things like that run from developer tools and see all the requests and how much they take and probably to give you some ideas when you can tune your app to run faster. Okay, so the first thing to do is just go and implement whatever Google page speed recommends you because they're all valuable recommendations. And if you have, let's say, a general e-commerce website, most of the cases it'll help because really, I've seen a lot of performance issues like slow website because your marketing department loaded some huge like five max images for product data and then you are trying to show it on the site. But you know, it doesn't work all the times and sometimes you need to go deeper. So first thing to take a look at this, check your JavaScript and CSS and use some bundling tools to minify it and in iSbuild have core and right now, I'm going to talk about iSbuild not core and usually what's applicable for core is applicable for classical.net, so you can use it first person. There's a build bundler nugget package and what it does is just built-in tool for bundling and you create a config file and describe what JavaScript and CSS are going to bundle and it works and in your view, you can use environment tech helper and say, okay, if I'm on development mode then just render all script back for me without bundling and if I'm in production mode then bundle everything and do this obscure JavaScript. Of course you can use tools like grungub or webpack, it's all the same job for you, so it's up to you really what you want to choose here. And a few words about dependency management. Nowadays, the most popular dependency management tool for .net is nugget. It has integration with almost all editors and there's another tool called Packet, so it is an extension of a nugget and it can download packages from rather nugget, it can go directly from GitHub and so it works like similar to Go lang when it can just download some source code from GitHub and bundle it. Okay, so the next step, like once you modify to JavaScript, CSS, it's still slow, they go to your images and there are tons of libraries how you can work with images directly. For example, one of the most popular is image magic and there's the image magic.net that's a wrapper around image magic and native library. If you're running on Windows, if you're on classical.net world, you can use system drawing and system Windows media namespaces, but don't do that, they're quite poor for server-side rendering and they consume a lot of memory and so it's like, it's not recommended, just go with image magic.net, really. And there are other libraries, so there is dpgd, there's a competitor for image magic, and others, so that's all like nugget packages, you can check them. Okay, the next step, we are going deeper and we should implement HTTP compression, so it's like really almost no-brainer, free tool that can improve your performance. First of all, there is a built-in support for HTTP compression in .NET Core used to deploy the nugget package about response compression and you can use gzip and it also supports iCompressionProvider interface and you can implement your own compression if you like. If you are on Windows, you can use iS Dynamic Compression Module or if you are on Linux, you probably will do nginx proxy for your iSphere.NET Core app, so you can do compression on nginx side. iSphere.NET Core comes with its own web server called Castro, it's also open source and trust platform and it was built with high performance in mind and the latest, I think some performance checkup, so nowadays it's one of the most high performance web server available on the market. So, again, like everything in .NET nowadays, you install it through nugget, install server.gaster package and this web server was built on the EPUB library just to be iSynchronous from ground up and this is the same library that's used, for example, from Node.js and we all know that Node.js is doing great jobs for building APIs and stuff, especially when they have a lot of IO operations. The latest version, Custosol version two, can be used as a standalone web server or you can call it via reverse proxy. I personally call it via reverse proxy because I like nginx. The earlier versions of this web server wasn't recommended to be used as a standalone web server. Custos supports Unix domain in sockets, WebSupply and HTTPS, so if you're on Linux, I would suggest you to go with Unix domain sockets because it's bringing better performance and there are a few settings that you can tune. For example, you can set how many concurred connections the web server supports or, for example, you can set up how big your range body size should be and the interesting thing is the last one, mid-request body data rate. So Custosol is checking your connection speed between the web server and the client and by default, if connection speed is going lower than 240 bytes per second, web Custosol switched to gray spirit so it's waiting for five seconds for your client to improve the channel and otherwise just reject the request. Okay, so it's all quick fixes and easy to bring but it not always doesn't work. Works for, say, 60, 65% issues, but yeah, it's too deeper. So I love this recommendation. Really, developers are expensive and depending on the country, they're rather expensive or very expensive. So just buy more hardware and vertical scalability helps somehow sometimes. So just take it. Buy bigger server, more RAM, more CPUs and probably it will help your project. I also have some cache on developers. Also, if you're running in a cloud and that's easy to do with iSphere.core, it has Docker support so usually what I'm doing, when I'm building applications nowadays, I just build Docker packages so I deploy my apps to this Docker, bring an image and just deploy to Azure to the AWS and scale it as needed. Also, if you are using one of those providers, Azure, AWS or Google App Engine, all of them support iSphere.core native now and I think for AWS you can build even like lambdas in C-Sharp and Docker.core. So it's like all available and people use it. Okay, so vertical scalability doesn't work or might be enough for the belief you already have a lot of hardware. So in this case, let's go and take a look what's going on in our HTTP request and what's going on on the page. The tool I'm using is called Mini Profiler. So basically it's a package that you put to your website and it intercepts into your HTTP pipeline and handles what's going on. The tool was developed by Stack Exchange so those guys know what they're doing. And you can install Mini Profiler, this is the core of the system. And that's your basic tracking. And then you can install your own plugins. So there are these plugins for entity framework six and entity framework core if you are interested in what's going on in your ORM. There's a profiler DB connection that they really like a lot. So that's basically a plugin for your, if you're using an Adonette natively, for example, sort of date where framework or like like ORM, then you can install this and see what's going on inside. And there are packages that track your AMBC in particular so you can take a look how much time you spend on reading views or controllers. And it's like really simple to install. You just go install packages and do some little bit of duration and done. It all takes this. So we're in our website and you can see, okay, I see like on this controller and let's take a lot of time. And you can see that most of the time we spent like running some SQL. Then you can run your SQL Profiler, I'm sure gonna SQL Server Profiler and you can see what's been on the page and you can see like, oh yeah, I'm running like hundreds of SQL for what reason. So probably in this case, this is a sign that you're using your ORM in the wrong way and bring us to the next slide. I think if you're building an app, first you work with the database. You must know SQL. Of course you have like all bunch of ORMs like into framework is great, but then under the hood it runs SQL and you should know what your SQL is doing. There are different ORMs available in Russian. So actually, this is a timing different ORMs spent for making just simple local objects for 500 select statements. And so obviously I don't like roll the A to N to SQL data provider. This is the fast one. And the next one is DAPER. So DAPER is a micro ORM and it does nothing except match your SQL and mapping to your classes. That's it. And you really have to develop, like you write your SQL, you don't use link. And I love this talk, so highly recommend it. Okay. And so know what your ORM is doing. Okay. We did a lot of optimization on data layer like doing here and there. Still that didn't help us what we should do. Probably we have to think about caching and caching is good, especially if you have a lot of memory. And caching is widely supported on ISP.NET Core and it has different layer levels of caching. First of all, let's say I memory cache interface and it installed the caching memory nugget package. So it will allow you to do like memory caching in another server. If you're using a radius, for example, then you can have an implementation of IDistributed caching interface and we have radius and SQL server available out of the box. So in this case, you will have almost the same API as working with memory, but it will store two radios and your code just works. On the next level, so this was like a lower level. You're working with code and that's the next level you can do caching inside your views. So you're writing your views in razor syntax that looks like HTML. And you just say, okay, I wanna cache this chunk of code and then the rest will be done automatically like ISP.NET Core, so it will just do caching during the running time. And again, you have a choice, you can store in the memory or in your distributed cache like radius. There's also a response cache attribute. It's more for like caching fine tuning. For example, you have a controller and you want to cache HTTP caching attributes, then you just apply this attribute and configure it for how long you're gonna store the output of this controller. And if you wanna use this attribute, you have to install this package Microsoft-like-spot.NET Core response caching. Okay, so we did some caching. Our performance looks a bit better, but now we can start seeing that, okay, we have a memory leak because our memory spikes and goes beyond threshold. So the best question, do we have a problem with GC? Maybe like Microsoft did something obscure thing on GC and there's a bug in our platform. Let's go like to C++, I assume they're fix it. Thanks God, usually not the case. First of all, I mean, I just say something like do a quick introduction to .NET GC. So in .NET GC, the memory, basically you have three generation, one to one, one, zero, one and two. And basically all your objects, one they create as you go to generation zero. And then when you're running out of memory, usually a garbage collector just go and check what's in zero and freezing. Whoever survives in generation one and then from one to two. So usually in generation two, you have like this long-leaving object and usually they consume like a bit of memory. And there is also a large object cache. That's a special dedicated part of the .NET runtime memory where it stores huge objects. And it has, it does a special garbage collector to clean it up. Okay, and it doesn't have the support different modes of garbage collector. It's a workstation GC, server side GC. Since they're looking about web apps, they're interesting in server side GC. And also you can have a choice between like background for server side, you have a background GC. So it means it runs in like parallel and different threads and just like different threads are checking what's going on in your memory and uses foreground threads or background threads, for example, windows to clean it up. And in non-current GC, it means that you have, you stop your universe, do a clean up, memory clean up and then start again. So by default, when you're running a server app, you will have a server GC in the background mode and based on my experience, it just works fine. But if you want to change, and if you're on Windows and the classical aspect of that, then you should change back config file and you can choose your mode. Also on Windows and iOS, there is another option called GC streaming commit on low memory. And if you're running a hosting environment and you have a lot of small websites running on your one server, then this attribute should be true. It means that, this attribute means that when you are, when your GC runs and it doesn't, they freeze all the memory and it just keeps something for your app. And if you do like this GC dream commit on low memory, it means like when your memory goes more than it, memory consumption goes beyond 80%, then your GC like tries to really clean whatever possible. And just like, it's really heavy on that. Works well for small sites on one server, doesn't work well for like one large app. Okay, if you are on ISP.NET Core site, then there is a runtime config file where you can do the same settings and here you can basically change the same things. Okay, and if you're using Windows and you're on Visual Studio 2017, community edition, then you have all profiling tools available for you for free built into the ID. And there's the member provider. So here you can see I'm running in my app and you can run it in a debugger mode. You can take the snapshot of your current memory and then from this snapshot, you can see, okay, what objects I have and how many bytes were allocated for this object and then you can find out, okay, oh, I have a list of streams and it takes a lot of memory, so let's go to the code and see what's going on. And also, you can see the actual value but you can also do several snapshots and you can see the different sites, you can see what object, what type is growing faster and then try to know as you code and try to find something. And for example, in this small simple sample, there's this times list and you're just adding and adding some data over there. So, if you're in production, you cannot run your app in a debugger, really. Of course, you can do a remote debugging, you can turn it on or do snapshots, but it's not always applicable or available. There is a tool, but this is tool for Windows and it's like for 10 years old. It's called PerfView and all these dots. You can have a distance for Windows events and some kernel-side events and try to analyze what's going on and you can do it for your hardware, for software, for drivers, but also there is a support for .NET and here you can see, they've been asked this tool, okay, in what generation of my garbage collector we have more objects or here we're asking like, in what generation spent more time doing garbage collection? For example, if it will be some go on like on generation two and spend more time in garbage collecting this one, it means that something is really on going on here and something was wrong with our tool. We can also see where does application allocates memory so you can check, okay, I have my large object heap where you have like huge objects, you can see how much objects you have there and go deep inside. We can also see the data types as we saw in the profile in Windows Studio. Okay, so another approach what we can take is we can, let's say we cannot run a debugger on our live server. So in this case, we can use to winGDP or LDP depending on if you're in a Windows or Linux to natively like to have a memory dump and then just go inside the dump and see what's going on and debug this dump and then just mention it. For this is the example for winDPG so we just doing a memory dump and this is like the tool looks and then you have like bunch of commands, okay, lots of CLR means VeloadingSupportForward.net and then we can just go to the dump here, try to find like how much memory, like how many, so where are the allocations for my strings and then review what's going on. So that's quite useful tool. It takes time to pick it up but once you pick it up, you're gonna love it. Okay, I wanna spend like a minute talking about pagination because this is that problem I've seen a lot in Mayant. Nowadays, if you're doing T-Shark using link and in link you can, for example here, I'm, there's this database called because it's a link for InstaFramework and what it's doing is just take all the persons and dump it into memory and then we just use take operation to take 100 persons and that's a course of many memory leaks and you know, in this case just really, just go and direct plain SQL. That's easy, straightforward and you will reduce your memory consumption. There's a tool called, in sb.core 2.1, this latest version, Microsoft introduced a new type called SpendT and the goal of this type is to bring array interface that works across different types of memory. For example, you can use kind of array operations for your memory, like non-pronated memory, non-managed memory that allocates and you use stack and for example, you can use memory type that can take this, just take memory and bring it to your sync operation and you can do like all greatest stuff is memory. Just recommend to take a look if you do like a memory operations apps. Okay, so, well, we don't think about manual memory management. Yes, it doesn't manage the environment, but you can do that. First of all, there's a big reference type and it works in a way that if you have a lot of objects but you don't care if it survives or not survives you can create those for just a big reference. It means the garbage collector may kill this object without you knowing it and even if somebody's reference it, the garbage collector can kill it and it helps somehow. There is also GCC settings latency mode and you can set up your garbage collector to be like a low-level latency. It means you are, in this case you are going to, you can say that you allocate a lot of small objects for example and please don't run garbage collector for me this time and don't try to stop running the garbage collector. And it works well for small objects but don't do it for large objects because you will just break your app and once you're leaving GCC latency mode, low latency, you must call GCC collector to free up your memory. There's also no GCC mode so you can have a section in your code and say, okay, I don't want the garbage collector to run here and you just annotate your code and let's call it without garbage collection. And in core CLR, this is actually not the core runtime, now there's a possibility to bring your own garbage collector and there's some home heat hub down here how you can build like a no GCC GCC I think it brings a lot of opportunity to the future. Okay, so we did some GCC tuning but our application seems to be slow. So the next question is like what's going on and I will, personally I would probably go to IO operations and not network operations to see what's going on over there. Again, mini profiler can help us with that. So here you can see that our controller calls check status method and it takes a lot of time. Then you can go to this method and use profiler API to annotate, okay, I wanna take a look how much time we're spending on calling this particular request. And after that, in your log, you will see, okay, in my check status method, we are spending 5,000 plus milliseconds just to call it an API. So yeah, something is going on wrong here. Then again, this is like in development mode stage environment, then you can run your Visual Studio profiler and run a code profiler. And in this case, you will see, okay, what the duration is called and how much the stake. So you see there's an API code. I haven't got the BTP file here, so it's just some obscure number in memory. But here you can go down and see where exactly it's called and even go right to your source code and see, okay, we are spending most of the time calling this particular API. And as you can see here, there's I think a way, there are I think a way keywords in C-Sharp and they allow you to bring some asynchronous operations. For example, if you're calling somebody over the network, you don't want your web server to wait till your request is done. It's like in Node.js, for example, and you are calling this code asynchronously. But the truth is, you are thinking, okay, I'm calling it asynchronously, probably I will have a great, better performance. It doesn't, the case, as you can see in this example, because it doesn't matter if you're calling it asynchronously or synchronously, it will take the same amount of time to execute. It doesn't matter of how your threads are managed by your web server. So .NET has a password library. They have it for a long time. It's available on the Cornell. It allows you to do some asynchronous operations. You can do like run stuff in parallel or you can do like you're really in sync. Okay, I wanna run my code, paralyze it by and chunk it and then do like parallel map reduce, all type of things. But you know, don't go crazy with that. And that's my next slide is, I think the way it says faster, but it's not guaranteed. So asynchronous operations doesn't mean that you will have like super fast app. First of all, if your code is doing a lot of IO or network operations, that is great candidate to choose asynchronous stuff because usually spend time on like the network latency or like really for my hardware. But if you're in calculation, I work for finance industry for years and like what I read hard is like when you're trying to calculate something, just do it like a single thread really because in this case, you're not going to spend, your CPU is not going to spend time like on context switching because let's say if you have like for calculating some formulas and sometimes you can be in a situation that your actual code takes less time for the context switching in your CPU, don't do it right. So also I think a way that's helpful if you're running like a long running operation and you want to have the ability for the user to cancel it possibly well and easy to implement. And yeah, context switching helps you run faster but not always, as I said. And you know, don't please don't make your all operations all methods asynchronous. It just doesn't work this way. Okay, so this is I think a way then TPL and if you're going to scale up even more then you should talk more about that message queues and microservices. And that's like, if you are at this point of time so hopefully your app is really popular and it brings in money so you have budget to do it. And dotnet was on the market for years and there are APIs for almost any in queue through any in queue server you can find as market. Like you can use Redis, like recent exchange, zero queue, Kafka, Solace, whatever. And there are also on top of those MQ libraries there are service bus implementations. The most popular is service bus. So basically they bring your framework and you can build your services on top of those framework and you have the API that will allow you allow your services to communicate to each other. And for the mass strategy, this is kind of quite popular nowadays. Okay, so I think that's all about my quick introduction and let's summarize the stuff. First of all, when you're doing something, you're doing something, think about return of investment and how much money you'll make out of it or how much money you'll make out of it. It depends on the project. If you have a performance issue on a web app, run Google page speed and those tools and they will have a lot. Vertical scalability is not bad, it's usually good and it might be a quick win. And check databases, know SQL and know how database works. If database doesn't help, then think about memory profiling and GC tuning, but it's like, yeah, it's kind of like magic sometimes. And I personally try to avoid this if possible. So caching and think about MQ solutions if the project is getting really complicated. Thank you and yeah, we still have two minutes for questions. So you mentioned that we can use Astrodot.net for creating cross-platform apps. Yes. So the last talk was important and I know there are many more platforms that we can use to create cross-platform apps. So is there any catch in using Astrodot.net or is there any benefit that will help me out in using Astrodot.net? Okay, yeah, okay. First of all, I love C-sharp language, language is awesome. It just brings you a functional programming paradigm and object-serving programming paradigm and you can mix them together. And they have like a really nice thing, like a link for example. So you are declared to be dealing with your collections. In terms of performance, I think Microsoft has like, they were trying to hire a lot of guys who are working on Node.js and some NGNs. So they have a really qualified people for building ISP for building like high-performance, high-scalable apps. And otherwise, it's just easy to use. Like, especially if you are on Visual Studio, I'm not selling it now, but like, if you have Visual Studio, it's just like, it runs smoothly. And I was playing with Ryder recently and it looks like it's even better. So, you know, like, in my opinion, it was built with a kind of, to make your app faster. So, yeah, it's just like, it's more like a time to market, so build it fast. No questions about it? Yeah, no more. Awesome. So if you have any question about .NET Core and I have around Linux, just send me a message. Thank you so much. Thank you.