Scale By The Bay 2018 Unconference: Taro L Saito
Recording: Scale By The Bay 2018 Unconference: Taro L Saito
okay I'm going to which is a lightweight braiding books for Scala let me explain a little bit about me so he knows me but you don't know about me so I'm an engineer at Tojo data a unique point about me is I have research background on database system and I was doing genome science when I was working at the academia for a while after that I moved to my my assistant Mike area to engineer and mom joined Twitter data which was a startup company recently acquired about arm Army's chip design maker I'm now reading query entity inside I'm Giorgio Tatum I'm an octave always stable pub I'm going to talk about areum today and I also built SQL SQLite JDBC which only has collected collected more than thousand feet upstairs I'm developed a table snappy jabber which is used inside spark as a compression reliable is so if you however used spark but you are using my code somewhere and I also published SVG so type probably which is used Muslim by Muslim is 2000 it was 3000 project in kind sky project so that's it so today I'm going to talk about airframe so you can access this repository at period airframe which is a lightweight building boxfuls coop and actually this is a collection of lightweight modules that can be used for building any types of application this is a production ready we've been using this for model two years so yeah it's it's okay to use compared to the other talks yeah hard today but any it's actually based on my cold collection since 2009 which is initially between Jabba but I gradually migrate to all the color base to skull because I yeah from writing Scott also repackage everything into evil ed dot airframe motive in 2016 and this is for maintainability because we need to list a lot of course built binary sportscar 2.11 2.12 so there many module inside there from country it has eighteen modules and that can be useful for simplifying adele programming here is a list of every module so airframe config you can read configuration with about between llamo fire every launcher is just a simple command line program launcher library on the many useful libraries including object serialization and also for debugging your applications that working by bobby matrix library j makes more time library so the many things the today's main topic is about dependency injection you can use also build HTTP server by using a frame vinegar-based HTTP server implementation is over in crete so but before jumping into dependency injection i want to show some of the yeah modules that is not useful for debugging your application for example a framework is simplifying europe application logging you just need to extend log support to it which is different in airframe then after that if you write in for something welding something you can see this kind of colorful log additional good thing about this is you can see the source code of location with that no performance overhead because these Orion codes are generated at compile time by uses chemicals well you can find more details in my blog post on medium another thing is air frame launcher so you you usually need to write a startup script over your application but you need to pass several command-line option every and learn to simplify this process but you can create a class that have several optional meters help message options or if we want to build a server you may need to specify port number this option can be specified like this command line then command line is translated into cross-functional arguments so thank you you can automatically bind these data types into just a story into command or a function argument so if you need to debug remote JVM process you usually need to use JMX so read about by adding disk disk and annotation you can monitor the internal state over the program your program by using some Jake console then you can touch see to the remote J billion processor you can check the internal state just by adding this annotation you can also use data talk data doc has a nice - who periodically check in JMX metrics so you can dump matrix every minute or every thirty seconds or so to create a beautiful dashboard every matrix this is another module it provides human readable data format including time duration data size it nice thing about this module is it contains creative time window string with employee for swim debt processing you usually need to space for some time rental about last minutes or the last five minutes that's today or last week but specifying exact date is a little bit annoying so you usually need to specify be a tip time when beginning from now to last day or last week last seven days so by providing this kind of string representation time window you cannot exact time range like this so yeah this is a main topic I think I have plenty of time and if you have any questions please feel free to interrupt the composition twist goal is learning how to use airframe dependency injection as a bonus I want to make sure you want you understand what can be simplified with the dependency injection I'm going to present five typical design patterns by using the dependency injection that is very helpful to improve the thought process or what you are calling scholar and actually to meet many many articles about dependency injection with a bomb among the famous round is written by Martin Fowler in Belgium control and you can find many articles in stock over four week barrier we also have many dependency injection framework something like spring Google juice cow d-mac wire crafter well too many frameworks so unless some people also proposes no free market protease just using pure scholar called to perform dependency injection its current situation is kind of quite confusing you will have too many too much information but you still cannot understand what is dead yes recently Adam Watsky what a really nice article to explain what is dependency injection it try to simplify the definition it provide a definition with dependency injection but dependency injection is the process of creating static state rescue service always every service parameterize by disparity I don't make sense in this face if you did this article carefully proper you can understand what he means but it's quite difficult to understand what is d so we need to see our thought process rhythm rather than to try to understand what is di we should think about what can be simplified by using gear so I'm going to show that by expelling how to use airframe then what can be simplified by using airframe so the usage of airframe is quite simple just you need to import we with airframe package then for you need to write this kind called if you trade application requires XY and z then use CP needs to bind this object to change the actual implementation you can define your design design freedom if you want to specify the concrete instance to X you can use by text to instance something if you want to make Y as a single tone yeah you can just specify to singleton if you want to switch to implementations of V you can specify that vector then what you need to do is from the design building the building a concrete instance of application then you can use application so that's that it so you only need to learn since three steps bind design on the bill that's all but by using these simple patterns we can yeah we found many many useful sort of design patterns in using airframe so pattern zero is just a just a basic but there many patterns I'm going to explain all this one by one first a basic is in airframe you can use two types of two ways of building object one is constructor injection and secondly is incorrect injection so constructor injection is just like a regular Scala classes so if you have a application that has a PP config object you can like this come see if you want to use trade in your application just bind the conciliation like this on how to build my new application is the same for both constructor injection into it injection so just create a new design and binding some configuration and just be read so what can be simplified by using this pattern actually if the previous example was very simple wrong but in real world you need to build a lot of lot of complex objects with ample you think about two classes like a and B which going to use database client on some fluent video which is a object talking library if you have a database you may want to have connection pool and actual database tourism if you were starting up some database you also want to have some monitor monitoring process of the database but we are working the logic around a and B you only need to care usually need care about direct dependencies so these are indirect dependencies you usually don't need to should not care about these complex details of your application so by using airframe you can focus on only this part because err friends buying cinders allows you just inject necessarily interface to your service so for implementing a you only need to decry on the interface on who and DiLaurentis implementing be you only need to care about who ended Korea but actual implementations like this there are many many complex details can be hidden if you don't use any frame lock but why you need to write this kind of complex object nesting overwriting so the upper one is an example without using airframe lower part is when you use same so the many story to define a database service a which uses database client who entered a client probably unity past some configuration to the connection to database connection configuration but you also need to care about initialization order of configuration because when creating database monitor instances there's no guarantee that the database connect configuration is initialized here so probably you need to use a lazy variable over something to the lazy initialization but if you use that air frame you can simplify you can hide this complexity behind the scene so that is ones up at the bar native abusing airplane and also not so tricky seeing in building application is you usually want to configure individual modules for example if you have an HTTP client you also want to configure HTTP client horrible how many connections we are going to use how many how long the timeout is so this kind of configure be necessary and when using database you also need to specify database configuration hosting an important name credential using data it's connection we also need to configure to use to specify the size of cosmic connection foods but if you need to pass this configuration you need to like this kind of conflicts nested initialization call so actually we're writing a and B you don't need to care you don't want to care about these nested object construction so by using a VM you can forget about how to construct all set because every M construct opposite on your behalf so that is yeah one of the other point is so I'm going to show you some of the design pattern we found in air frame in every adding configuration of your module is quite straightforward because if you define a connection pool hobbies you can immediately define your configuration here because you don't need to think about how to pass this configuration object writable collection period configuration is over there but in writing a LV there is no connection pool configuration to not appear in the code so actually this looks quite simple but it's not larger in innovative so by using bind then let air frame past the configuration won't be help you you can simplify the thought process when you writing this kind of code so you can put the configuration really closest press enter code so that is one of the other point is another thing is you usually want to test the code by switching some database implementation into in-memory database or you if you don't want to make any network connection proper you just use in-memory loading implementation instead of using HTTP connection so to switch this kind of information you can simply need to tweak the design of airframe for example based on the previous design you you only need to see database implement some infinitely implementation or HTTP client information can be just done in memory yoga or something the how to use a is the same you don't need to care about differences between object construction for testing or production you just you can just open like someone's a dependency when test writing test code another thing another good thing about airframe is you can manage lifecycle or object or services are quite a treat airframe support on start or on shutdown lifecycle folks so when creating a connection pool you want to start the connection pool yes finishing the application you want to close the connection properly you can also use J so 250 annotation something like this post construct previously which is also using Google's Google juice yeah both ways works for initializing or terminating services what is good about this is in real world the initialization and termination order is quite complex so example when building this kind of application database need to be ensured fast there we are going to start database monitor after that we are going to start connection to data based client and service a so the auto initialization is yeah usually deep nested leaf child instance it should be the first the yeah application is who actually using these components will be the last one then every managed this kind of order by looking at on start Chadron on stat lifecycle work so if this is called the instance is your registers in this order when closing FM sessions on Saturday folk will be called but the order is the livers of the initialization so it's basically faster in last out or the final order so that means when finishing the applications that use a and B so if B is terminating you can't close this fluently dova yet because this is also used by a so you need to wait it's finished after air finishes you can call this and biiig for in that you may want to close the database but DB monta is still using so you need to wait for a while until so the dis managing this kind of dependency or lifecycle management order is quite complex so it's actually from the tag and direct acyclic graph so but um builds the object on your behalf so it can track the order of object initialization so you don't need to care about this order airframe takes care of that so that is quite interesting thing about the other interesting pattern we found in airframe is you can mix in Scott rates example you can define database current service like this you can't define fluently current service degrees then you can mixing by using Scott rates functionality to build a complex application if you want to use yes all this vacation want to access database and fluently logger the simple you can mixed we use the substrate you can also use constructor injection but it has some duplication of renaming unity apply some variable name here but you can reuse existing by if you define substrate so I'm named niblet it's a flower bundle pattern because you are going to combine various type of services by using mixing or SCARA this pattern is also quite useful if you add like full cycle management folks here you can be used and that database opening database closing can be reused so you don't need to define the same logic again in the game another pattern is if you want to create whatever multiple database connection about the configuration is slightly different but you want to share the same dinner data connection pool then you only want to configure some specific configuration of database so you can create instead of binding database directly you can bind the factory for building database so in this syntax that the best configuration can be changed later like this so if you want to connect going to database one of data less two you can simply call that factory generated by airframe so these patterns are important things in is element so in summary the assisting you can forget when using airframe you can forget how to be serviced objects so complex object instantiation process can be simplified by just using bind design-build process how to manage missile cycle which should be final order will be managed by airframe and also using FM is called simple so you you are going to forget how to use the use the you don't need to lead many many articles around a dependency injection if you want to if you need speedy eyes that's being put springy boots di you need to do the 10 page or more documents to understand what is what are they doing so simple uses it's quite an important part so yes you can forget three things how to be a service over said how to manage this complex file or using the I'd say so use yeah we still have some time so I want to show some of the internals by default airframe uses singleton body because most people want to use singleton by default singleton is not a global thing though it's a cost inside of sessions if you discard a session singleton order to be also discarded so it's sort of safe singleton in the airframe point instance instance is when you need to build object every time so if you don't want to create a single tone you can use this syntax when faculty already explained that design object that specify how to what kind of instances should be used inside you know object is in body is actually designed object is immutable on syllabus with Apple if you are using spark you can send design to remote worker node then you can delete the same over the construction process you can add many many designs to overlay previous designs so adding order is quite important in Ihram so you if you want to innovate a lot of service at once yeah you can use production mode or if you want to buy yeah if you want to if you don't want to show some of the lifecycle login you can hide some of the I said actually the internals of session via the code is quite compared so the first night of the cold session dot build square our a PP is extended this called like code like this by using scale macros so actually it's try to embed a session object inside too late a the inside third a if there is a binary synthesis yeah it try to find the session from session folder this session managed singleton was clear life cycles of the objects so yeah it's quite complex but so but the design philosophy of airframe if I wanted to add this kind of complexity as much as possible on this watch is a good a similar example this one is this watch is called simplicity and which is made by 54 of beer became legendary famous legendary watchmaker and Switzer a be part of the clock is built by himself but the look and feel is quite simple but internals is quite quite complex but in our users you don't need to care about these details how watch is built it doesn't matter for very inviting when using what so FM is actually try to do the similar thing providing simplicity for application developers that is the PFC design and also as a trick use the inside airframe is using Scala signature in sodium so if you have this kind cause if you use Java compiler you will because of tie pager you don't know what the element type of is this list but if you use Scala see skocy and skål signature inside your cross byte code so you can find concrete types or the best element in this case that is be FM is using disk it's classic to instantiate even you have for example didn't like type trades if you Java Java Sea you can't instance it B because there's no information about B but if you use yes signature you can instance it object of B so because we we also support type areas targeted or higher kinda stuff which is B which is useful for Chagas final patterns future work and summary is current version of AFM is 0.73 out of this month we already had 40 possibilities mostly there will be almost no API change just minor fixes the reason we are having so many frequent updated FM has 18 module we need to add a lot of functionality to other modules at random dependency injection and so we are also building a frame for scott 2.11 to point web 2.0 sorry and Scala GS is also supported by alpha but when I was using SBT vidas command the single single district SIA was because we need to build a teen module for each scholar compiler version also Scott years now I've gave up using SVG vidas probably just paralyzed it was testing for Scott went to the point able to point 22 points 13 in a moment okay then we can all these on me it is in ten minutes by using Travis Siri for details we can find my blog post on the medium three tips for maintaining scale project c oz ahmed samir talk five tips for keep maintain scale project like this so yeah okay that's it summary is to understand the eye you need to think about what you can simplify by using di how to be the object automatic life cycle orders how to use the iframe are easier yeah we explain these design patterns by using airway thank you that's it don't forget our detox life here it's just interesting thank you so