The Ultimate Dependency Manager Shootout Xander Uiterlinden Sander Mak @uiterlix @sander_mak ! Luminis Technologies Who we are Sander Mak http://branchandbound.net @sander_mak Xander Uiterlinden http://blog.uiterlinden.nl @uiterlix @uiterlix @sander_mak Agenda OSGi Services Dependency Managers Comparison Overview/community Code Performance Conclusion @uiterlix @sander_mak OSGi Services OSGi Services api + impl package dependency Provider Bundle! new MyServiceImpl() api.MyService impl.MyServiceImpl Consumer Bundle Strong coupling to implementation ! What if provider bundle not available/stops? ! What about configuration? @uiterlix @sander_mak OSGi Services only api package dependency Provider Bundle! Consumer! Bundle api.MyService impl.MyServiceImpl register OSGi Service Registry lookup Decoupling through interfaces Inversion of Control Service dynamics @uiterlix @sander_mak Dependency Managers Why Dependency Managers? @uiterlix @sander_mak Why Dependency Managers? Cut down the boilerplate Decouple from OSGi APIs Dependency Injection Testability Component models Aspects Adapters Etc. @uiterlix @sander_mak Components…?! ! org.apache.felix.ipojo.annotations.Component! org.osgi.service.component.annotations.Component aQute.bnd.annotation.component.Component! org.apache.felix.dm.annotation.api.Component! org.springframework.stereotype.Component! …. ! Notions: contract-based, reactive, explicit lifecycle Comparison The lineup Felix Dependency Manager Declarative Services Felix iPojo Blueprint Implementations Compendium Specifications @uiterlix @sander_mak Felix Service Component ! Runtime ! Equinox! ! KnopflerFish Eclipse Gemini Blueprint ! ! Apache Aries The lineup: disclaimer We primarily work with (and on) Felix DM @uiterlix @sander_mak Declarative Services Since R4 (2005) Bundle 1 DS 1.1 with R4.2, DS 1.2 with R5 reference XML based Component! Instance True POJOs Component! Description Bundle 2 Component! Instance Service provide Component! Description Or: DS annotations to generate XML ! Additional abstractions: ComponentContext for each component ComponentFactory: client initiates instantiation @uiterlix @sander_mak Felix SCR License Apache 2.0 Since 2007 Last release March 2014 User list ~50 msg Open issues 25 @uiterlix @sander_mak Eclipse Gemini Blueprint 2009 DM Server Gemini Blueprint 1 R4.2 (2009) SpecBundle since Bundle 2 Familiar for Spring devs Application Context Application Context reference Declarative: XML basedService Bean Bean Bean Bean Annotations in Aries, but not in spec (or Gemini) export Bean Components proxied: ‘Dampens’ service dynamics @uiterlix @sander_mak Eclipse Gemini Blueprint License EPL Since 2009 Last release August 2012 User list ~60 msg Open issues 17 Lots of 404s :( @uiterlix @sander_mak Felix Dependency Manager Service DSLBundle for component definition inBundle Activator 1 2 Programmatic Component! Instance aspect reference Component! Instance Annotation based Service (bnd plugin) adapt Embraces service dynamics Service’ Component! Instance publish Additional abstractions: Aspect: intercept and republish service Adapter: publish service with adapted interface @uiterlix @sander_mak Felix Dependency Manager License Apache 2.0 Since 2004 Last release Januari 2013 User list ~1 msg Open issues 22 @uiterlix @sander_mak Felix iPojo Bundle 1 Bundle 2 Programmatic API, XML and annotations Proxy based provide Component Component Bytecode manipulation Service ! require Component! instance Component! instance Additional abstractions: Composites: intra-bundle mechanism ! Scoped service registries Pluggable handlers @uiterlix @sander_mak Felix iPojo License Apache 2.0 Since 2008 Last release March 2014 User list ~130 msg Open issues 30 Best site among DMs! @uiterlix @sander_mak Comparison: code The example http://bit.ly/dmshootout @uiterlix @sander_mak Extender pattern Service Registry Some-Header: … Application bundle 1 Application bundle 2 Application bundle 3 @uiterlix @sander_mak register services SCR/iPojo/Blueprint/(DM! runtime) bundle Declarative Services Temperate Sensor Bundle META-INF/MANIFEST.MF! OSGI-INF/temp.xml! ! TemperatureSensor.class @uiterlix @sander_mak Declarative Services Dashboard Bundle @uiterlix @sander_mak Declarative Services No direct field injection Defaults: Delayed component (activate on use) Static policy -> many reactivations ! What if ! ! ‘better’ service arrives? @uiterlix @sander_mak Static Dynamic Reluctant Do nothing Rebind optionals Greedy Reactivate Rebind BluePrint Temperate Sensor Bundle META-INF/MANIFEST.MF! OSGI-INF/blueprint/temp.xml! ! TemperatureSensor.class @uiterlix @sander_mak Bundle-Blueprint header optional BluePrint Dashboard Bundle @uiterlix @sander_mak snipped 10+ lines of namespaces :( BluePrint ! Strong focus on intra-bundle composition Hides dynamicity (until TimeOutException…) If dependency goes away, component is not stopped. If service is exposed, unregisters it. No lazy activation like DS Whole ‘applicationContext’ started or not (Custom) TypeConverters Constructor/setter injection, no field injection Namespace hell :( ! @uiterlix @sander_mak Felix Dependency Manager Temperate Sensor Bundle META-INF/MANIFEST.MF! ! Activator.class! TemperatureSensor.class @uiterlix @sander_mak Felix Dependency Manager Dashboard Bundle @uiterlix @sander_mak Felix Dependency Manager It’s code: dynamically create and depend on services Annotations available (+ bnd plugin) Field injection, NullObject pattern Manual mgmt. of list of dependencies :( Services registered eagerly from Activator Features: aspects, adapters ! DM 4 coming up… @uiterlix @sander_mak Felix Dependency Manager https://bitbucket.org/uiterlix/ravioli ! @uiterlix @sander_mak Felix iPojo Temperate Sensor Bundle ! TemperatureSensor.class! metadata.xml! ! META-INF/MANIFEST.MF! Generated by IDE plugin by processing annotations and metadata.xml @uiterlix @sander_mak Felix iPojo @uiterlix @sander_mak Felix iPojo Both ‚static’ configuration and configuration using code Dependency manager with the most advanced features: External handlers Service binding interceptors Stereotypes Annotations limited to declaring components and ‚simple’ instances. XML recommended for declaring instances. Shell commands for component inspection ! @uiterlix @sander_mak Comparison: performance Benchmarks Don’t be afraid of too many services ? Promises… ! „Each bundle may register zero or more services. Each bundle may also use zero or more services. There exists no limit on the number of services, more than the ones given by memory limits or java security permissions.” (Knoplerfish tutorial) @uiterlix @sander_mak ! Benchmark scenario ! Temperature sensors for each postal code in the Nederlands 463860 Sensor services ! Service properties: - Province - Municipality - City - PostalCode @uiterlix @sander_mak Benchmarks Publishing Sensor services Felix, Equinox, Knoplerfish Plain OSGi, DM, iPojo ! Consuming Sensor services Whiteboard; all sensors in Amsterdam (&(province=Noord-Holland)(municipality=Amsterdam)) Felix, Equinox, Knoplerfish DS, DM, iPojo, Blueprint @uiterlix @sander_mak Disclaimer Results are as-is, no further investigation done No optimizations done ! You can repeat these tests yourself. Projects are available on github http://bit.ly/dmshootout @uiterlix @sander_mak Register services (Equinox) OSGi 700000 DM iPojo ipojo Duration in ms. 525000 350000 175000 0 10000 30000 50000 70000 90000 110000 130000 150000 170000 190000 210000 230000 250000 270000 290000 310000 330000 350000 370000 390000 410000 430000 450000 @uiterlix @sander_mak DM OSGi Register services (Felix) OSGi DM iPojo 250000 iPojo 200000 150000 100000 50000 0 10000 30000 50000 70000 90000 110000 130000 150000 170000 190000 210000 230000 250000 270000 290000 310000 330000 350000 370000 390000 410000 430000 450000 @uiterlix @sander_mak DM OSGi Register services (Knoplerfish) OSGi DM iPojo 250000 iPojo 200000 150000 100000 50000 0 10000 30000 50000 70000 90000 110000 130000 150000 170000 190000 210000 230000 250000 270000 290000 310000 330000 350000 370000 390000 410000 430000 450000 @uiterlix @sander_mak DM OSGi Register services (combined) OSGi equinox OSGi knoplerfish DM equinox DM knoplerfish iPojo equinox iPojo knoplerfish OSGi felix DM felix iPojo felix 700000 iPojo Equinox 600000 500000 400000 300000 iPojo Felix & Knoplerfish 200000 OSGi & DM Felix 100000 0 10000 30000 50000 70000 90000 110000 130000 150000 170000 190000 210000 230000 250000 270000 290000 310000 330000 350000 370000 390000 410000 430000 450000 @uiterlix @sander_mak OSGi & DM Equinox & Knoplerfish Register services Observations Non linear results for registering services with Felix Registering services using iPojo takes considerably longer compared to plain OSGi and DM @uiterlix @sander_mak Consuming services Injecting 19021 services into a single consumer on Equinox 1600 Time in millis 1200 800 400 0 @uiterlix @sander_mak blueprint dm ds ipojo Method invocation overhead Injecting 19021 services into a single consumer on Equinox, and invoking a method on the injected services injection injection and method invocation 1600 Time in millis 1200 800 400 0 @uiterlix @sander_mak blueprint dm ds ipojo iPojo and # of services Injecting a single service into a single consumer on Equinox iPojo 60000 Time in millis 45000 30000 15000 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 # services in service registry @uiterlix @sander_mak Performance considerations Use of LDAP filters Filter complexity, service registry scans Felix DM provides optimization though indexing service properties ! Default With index 300000 225000 150000 ! Bundle starting order 75000 0 197 Service tracker obtain initial versus service listener events @uiterlix @sander_mak 2878 Conclusion Conclusion Features ranging from simple to advanced (DS, Blueprint < DM < iPojo) Annotation/XML-only frameworks are easy to use but provide less dynamics Consider the expected size of your application (services, dependencies) and run some test before choosing one! You can mix & match … but don’t do that @uiterlix @sander_mak Questions? Code: http://bit.ly/dmshootout Sander Mak http://branchandbound.net @sander_mak Xander Uiterlinden http://blog.uiterlinden.nl @uiterlix @uiterlix @sander_mak
© Copyright 2024 ExpyDoc