building linkedin's next generation architecture with osgi

37
OSGi Yan Pujante Distinguished Software Engineer Member of the Founding Team @ LinkedIn [email protected] http://www.linkedin.com/in/yan Building LinkedIn's Next Generation Architecture with OSGI

Upload: linkedin

Post on 10-May-2015

17.163 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Building LinkedIn's Next Generation  Architecture with OSGi

OSGi

Yan PujanteDistinguished Software Engineer

Member of the Founding Team @ [email protected]

http://www.linkedin.com/in/yan

Building LinkedIn's Next Generation Architecture with OSGI

Page 2: Building LinkedIn's Next Generation  Architecture with OSGi

Background■ LinkedIn created in 03/2003

• close to 30M members

• profitable with 5 revenue lines

• HQ in Mountain View (400 employees)

■ Technologies

• 2 datacenters (~ 600 machines)

• SOA, java, tomcat, spring framework, http, Oracle, MySQL, servlets, jsp, graph, OSGi...

• dev on MacOS X, prod on Solaris

Page 3: Building LinkedIn's Next Generation  Architecture with OSGi

Challenges

■ Growing engineering team on a monolithic code base (still modular)

■ Growing product team wanting more and more feature, faster

■ Growing operations team deploying more and more servers

Page 4: Building LinkedIn's Next Generation  Architecture with OSGi

Back-EndFront-End

tomcat

webapp

1

2

3

N4

Pjetty (1)

webapp

X

webapp

Z

webapp

Y

jetty (2)

webapp

M

webapp

N

webapp

R

Challenges (SOA in dev)

■ Front-end: many BL services in one webapp (in tomcat)

■ Back-end: many wars in 5 containers (jetty) with 1 service per war

■ Note that prod and dev are different

Page 5: Building LinkedIn's Next Generation  Architecture with OSGi

Container Challenge

■ 1 war with N services

• does not scale for dev (conflicts, monolithic...)

■ N wars with 1 service

• does not scale from a container point of view (no shared jars)

■ Can add containers but only 12Gb of RAM :(

Page 6: Building LinkedIn's Next Generation  Architecture with OSGi

Challenges (SOA in prod)

■ Upgrading back-end service to new version requires downtime

• Hardware LB does not account for version

■ Upgrading front-end service to new version requires redeploy

• N services in 1 war

■ Adding new back-end service painful

• lots of manual configuration (LB, front-end...)

Page 7: Building LinkedIn's Next Generation  Architecture with OSGi

Solution: OSGi

■ Belief that OSGi is one of the tools that will help us address those challenges

Why OSGi?

Page 8: Building LinkedIn's Next Generation  Architecture with OSGi

OSGi intro

■ OSGi means “Open Services Gateway initiative”

■ OSGi is a spec with several implementations

• Equinox (eclipse!)

• Knoplerfish

• Felix (Apache)

Page 9: Building LinkedIn's Next Generation  Architecture with OSGi

OSGi intro (cont.)

■ OSGi has some very good properties

• Smart class loading => multiple versions jars ok

• Highly dynamic => deploy / undeploy built in

• Services registry

• Highly extensible / configurable

■ OSGi bundle = Jar File with OSGi manifests

Page 10: Building LinkedIn's Next Generation  Architecture with OSGi

OSGi bundle

Specification-Title: Colorado Software Summit 2008 Hello Wolrd ClientBundle-Activator: com.linkedin.colorado.helloworld.client.HelloWorldClientActivatorImport-Package: com.linkedin.colorado.helloworld.api;version="[1.0.0,1.0.1)", com.linkedin.colorado.helloworld.client;version="[1.0.0,1.0.1)", org.osgi.framework;version="[1.4.0,1.4.1)"Export-Package: com.linkedin.colorado.helloworld.client;version="1.0.0"Bundle-Version: 1.0.0Bundle-Name: colorado-helloworld-clientBundle-ManifestVersion: 2Bundle-SymbolicName: colorado-helloworld-clientBnd-LastModified: 1224557973403Generated-On: 20081020Tool: Bnd-<unknown version>Implementation-Version: DevBuild

Page 11: Building LinkedIn's Next Generation  Architecture with OSGi

BundleActivator

public interface ServletContextListener extends EventListener { void contextInitialized(ServletContextEvent event); void contextDestroyed(ServletContextEvent event);}

■ In a war: ServletContextListener

web.xml <listener> <listener-class>com.colorado.MyListener</listener-class> </listener>

■ In a Bundle: BundleActivatorpublic interface BundleActivator { void start(BundleContext bundleContext) throws Exception; void stop(BundleContext bundleContext) throws Exception;}

MANIFEST.MFBundle-Activator: com.colorado.MyActivator

Page 12: Building LinkedIn's Next Generation  Architecture with OSGi

BundleContext

■ The bundle context is the entry point:

• registerService / getServiceReference => to register / get services from registry

• addBundleListener / addServiceListener => to listens / extends the framework

• even installBundle !

• ... and more

Page 13: Building LinkedIn's Next Generation  Architecture with OSGi

Demo

■ Equinox demo... stay tuned...

Page 14: Building LinkedIn's Next Generation  Architecture with OSGi

Web Container

■ Services exported with Spring/RPC

■ Services in same war can see each other

■ Share the jarsVM

WEB Container

WARJARs

Services

SpringRPC

HTTP

Page 15: Building LinkedIn's Next Generation  Architecture with OSGi

VM

WEB Container

JARs

Services

SpringRPC

HTTP

JARs

Services

SpringRPC

Web Container

■ Cannot share jars

■ Cannot talk directly

Page 16: Building LinkedIn's Next Generation  Architecture with OSGi

VM

OSGi Container

Service Registry

Bundles

OSGi container

■ Bundles (jars) shared

■ Services shared

■ Dynamic replacement of bundles

• OSGi solves the container challenge

Page 17: Building LinkedIn's Next Generation  Architecture with OSGi

Distributed OSGi

■ OSGi is currently container centric

■ Next version (4.2) will introduce distributed OSGi

• What do we do in the meantime ?

Page 18: Building LinkedIn's Next Generation  Architecture with OSGi

LinkedIn distributed OSGi

■ Service ‘red’ talks to service ‘green’ (local)

• What happens if we move ‘green’ to a different container ?

Service

Registry

VMC1

Service Registry

Bundles

Page 19: Building LinkedIn's Next Generation  Architecture with OSGi

VMC3

VMC2

Service

Registry

VMC1

Service Registry

Bundles

Bundles

Bundles

Service

Registry

LinkedIn distributed OSGi

Page 20: Building LinkedIn's Next Generation  Architecture with OSGi

VMC3

VMC2

VMC1

Service Registry

Bundles

2

2

Bundles

Bundles

Service

Registry

Service

Registry

LinkedIn distributed OSGi

Page 21: Building LinkedIn's Next Generation  Architecture with OSGi

VMC3

VMC2

VMC1

Service Registry

Bundles

2

2

Bundles

Bundles

Service

Registry

Service

Registry

3

3

LinkedIn distributed OSGi

Page 22: Building LinkedIn's Next Generation  Architecture with OSGi

VMC3

VMC2

VMC1

Service Registry

Bundles

2

2

Bundles

Bundles

Service

Registry

Service

Registry

3

3

LinkedIn distributed OSGi

Page 23: Building LinkedIn's Next Generation  Architecture with OSGi

LinkedIn distributed OSGi■ no more N-1 / 1-N problem

• libraries and services can be shared in 1 container (mem. footprint smaller)

• services shared across containers

■ transparent location to clients

• no more configurations to change when adding/removing/moving services

■ software load balancer

• much more flexible (handle version)

Page 24: Building LinkedIn's Next Generation  Architecture with OSGi

LB and version

VMC3

VMC2

VMC1

Service Registry

Bundles

22

Bundles

Bundles

Service

Registry

Service

Registry

3

3

Page 25: Building LinkedIn's Next Generation  Architecture with OSGi

Everything is perfect...

■ ...Not really

• OSGi has some problems

Page 26: Building LinkedIn's Next Generation  Architecture with OSGi

OSGi problems

■ OSGi is great, but tooling is not quite there yet

■ Not every lib is a bundle

■ OSGi was designed for embedded devices => using it for server side is recent (but very active)

Page 27: Building LinkedIn's Next Generation  Architecture with OSGi

OSGi problems

■ OSGi is quite low level => but there is some work to ‘hide’ the complexity

• spring DM (spring dynamic module)

• multiple vendors containers

■ Spring DM Server, Glassfish, Infiniflow

■ OSGi is container centric, but next version will add distributed OSGi (although no support for LB)

Page 28: Building LinkedIn's Next Generation  Architecture with OSGi

OSGi problems (cont.)

■ version management can be nightmarish

• Import-Package: com.linkedin.util;version=1.0.0

■ version=1.0.0 means [1.0.0, ∞)

■ should use at least: version=[1.0.0,2.0.0)

■ runtime is dynamic and can result in untested code being executed!

Page 29: Building LinkedIn's Next Generation  Architecture with OSGi

Runtime version problem

■ client1 and client2 uses Service 3.0.0

■ Dependencies are ‘loose’: [3.0.0, 4.0.0)

Page 30: Building LinkedIn's Next Generation  Architecture with OSGi

Runtime version problem

■ We upgrade client1 and service

■ client2 starts using green bundles

■ => Most likely untested

Page 31: Building LinkedIn's Next Generation  Architecture with OSGi

Runtime version solutions ?

■ A solution is to lock version:

• [1.0.0,1.0.0] => no slack

• [1.0.0,1.0.1) => tiny bit of slack for emergency mode

■ Does it really work ? spring 2.5.5 imports hibernate version [3.1,∞)

■ Can OSGi even resolve with everything locked down ?

Page 32: Building LinkedIn's Next Generation  Architecture with OSGi

Runtime version problem

■ With maximal lock-down, client2 cannot use the new service

Page 33: Building LinkedIn's Next Generation  Architecture with OSGi

Runtime version solutions ?

■ Services cannot talk to each other directly => need serialization for backward compatible services (dynamic proxy)

Page 34: Building LinkedIn's Next Generation  Architecture with OSGi

Despite problems...

■ ...OSGi and community moving in the right direction

Page 35: Building LinkedIn's Next Generation  Architecture with OSGi

Where are we ?

■ Bundle repository (big amount of work... in progress)

■ Use ivy/bnd for generating bundles

■ Evaluating container

• Infiniflow (from Paremus) most likely the one

• LinkedIn spring / SCA to deploy composites

■ Work on the load balancer/distribution (in progress)

■ Work on tooling / build integration (Sigil from Paremus)

■ Much much more to do...

Page 36: Building LinkedIn's Next Generation  Architecture with OSGi

Conclusion

■ Using OSGi... definitely!

■ But we do not want application developers to have to deal with it.

Page 37: Building LinkedIn's Next Generation  Architecture with OSGi

More information

■ Check my posts on the LinkedIn blog (OSGi series). More to come...