690 likes | 841 Views
Analyzing Interactions of Asynchronously Communicating Systems. Tevfik Bultan Department of Computer Science University of California, Santa Barbara bultan@cs.ucsb.edu http://www.cs.ucsb.edu/~bultan. University of California at Santa Barbara. Acknowledgements. Joint work with
E N D
Analyzing Interactions of Asynchronously Communicating Systems Tevfik Bultan Department of Computer Science University of California, Santa Barbara bultan@cs.ucsb.edu http://www.cs.ucsb.edu/~bultan
Acknowledgements • Joint work with • Xiang Fu, Hofstra University • Jianwen Su, University of California, Santa Barbara • Zachary Stengel, Microsoft • Samik Basu, Iowa State
Motivation 1: Web Services • Web services support basic client/server style interactions • Example: Amazon E-Commerce Web Service (AWS-ECS) • AWS-ECS WSDL specification lists 40 operations that provide differing ways of browsing Amazon’s product database such as • ItemSearch, CartCreate, CartAdd, CartModify, CartGet, CartClear • Based on the AWS-ECS WSDL specification one can implement clients that interact with AWS-ECS WSDL Request Service Provider Service Requester SOAP Response Server Client
Composing Services • Can this framework support more than basic client/server style interactions? • Can we compose a set of services to construct a new service? • For example: • If we are building a bookstore service, we may want to use both Amazon’s service and Barnes & Noble’s service in order to get better prices • Another (well-known) example: • A travel agency service that uses other services (such as flight reservation, hotel reservation, and car rental services) to help customers book their trips
Orchestration vs Choreography Orchestration: Define an executable process that interacts with existing services and executes them in a particular order and combines the results to achieve a new goal • From atomic services to stateful services • Web Services Business Process Execution Language (WS-BPEL) Choreography: Specify how the individual services should interact with each other. Find or construct individual services that follow this interaction specification • Global specification of interactions among services • Web Services Choreography Description Language (WS-CDL) A choreography can be realized by writing an orchestration for each peer involved in the choreography • Choreography as global behavior specification • Orchestration as local behavior specification that realizes the global specification
Web Services Standards Stack Web Services Choreography Description Language (WS-CDL) Choreography Web Services Business Process Execution Language (WS-BPEL) Orchestration Service Web Services Description Language (WSDL) Simple Object Access Protocol (SOAP) Protocol Type XML Schema (XSD) Extensible Markup Language (XML) Data WSDL WS-BPEL SOAP Atomic Service Orchestrated Service WS-CDL SOAP SOAP WS-BPEL WSDL Orchestrated Service SOAP Atomic Service SOAP
Asynchronous Messaging • Sender does not have to wait for the receiver • Message is inserted to a message queue • Messaging platform guarantees the delivery of the message • Why support asynchronous messaging? • Otherwise the sender has to block and wait for the receiver • Sender may not need any data to be returned • If the sender needs some data to be returned, it should only wait when it needs to use that data • Asynchronous messaging can alleviate the latency of message transmission through the Internet • Asynchronous messaging can prevent sender from blocking if the receiver service is temporarily unavailable • Rather then creating a thread to handle the send, use asynchronous messaging
Motivation 2: Singularity OS • Experimental OS developed by Microsoft Research to explore new ideas for operating system design • Key design principles: • Dependability • Security • Key architectural decision: • Implement a sealed process system • Software Isolated Processes (SIPs) • Closed code space (no dynamic code loading or code generation) • Closed object space (no shared memory) • Inter-process communication occurs via message passing over channels
Singularity Channels • Channels allow 2-Party asynchronous communication via FIFO message queues • Sends are non blocking • Receives block until a message is at the head of a receive queue • Each channel has exactly two endpoints • Type exposed for each endpoint (Exp and Imp) • Each endpoint owned by at most one process at any time • Owner of Exp referred to as Server • Owner of Imp referred to as Client
Channel Contracts • Written in Sing # • Contracts specify two things: • The messages that may be sent over a channel • out message are sent from the Server endpoint to the Client endpoint (SC) • in messages are sent from the Client endpoint to the Server endpoint (CS) • The set of allowed message sequences • out message marked with ! • in messages marked with ? publiccontract KeyboardDeviceContract { outmessage AckKey( uint key ); outmessage NakKey(); outmessage Success(); inmessage GetKey(); inmessage PollKey(); state Start { Success! -> Ready; } state Ready { GetKey? -> Waiting; PollKey? -> (AckKey! or NakKey!) -> Ready; } state Waiting { AckKey! -> Ready; NakKey! -> Ready; } }
Channel Contracts • A contract specifies a finite state machine • Each message causes a deterministic transition from one state to another state KeyboardDeviceContract publiccontract KeyboardDeviceContract { outmessage AckKey( uint key ); outmessage NakKey(); outmessage Success(); inmessage GetKey(); inmessage PollKey(); state Start { Success! -> Ready; } state Ready { GetKey? -> Waiting; PollKey? -> (AckKey! or NakKey!) -> Ready; } state Waiting { AckKey! -> Ready; NakKey! -> Ready; } } Start SC:AckKey SC:AckKey SC:Success Implicit State CS:PollKey CS:GetKey Waiting Ready Ready$0 SC:AckKey SC:NakKey
Outline • Motivation • Composition of Web Services • Singularity Channel Contracts • Conversations • Realizability • Synchronizability • Applications • Recent Results
Going to Lunch at UCSB • Before Xiang left UCSB, Xiang, Jianwen and I were using the following protocol for going to lunch: • Sometime around noon one of us would call another one by phone and tell him where and when we would meet for lunch. • The receiver of this first call would call the remaining peer and pass the information. • Let’s call this protocol the First Caller Decides (FCD) protocol. • At the time we did not have answering machines or voicemail!
FCD Protocol Scenarios • Possible scenario • Tevfik calls Jianwen with the decision of where and when to eat • Jianwen calls Xiang and passes the information • Another scenario • Jianwen calls Tevfik with the decision of where and when to eat • Tevfik calls Xiang and passes the information • Yet another scenario • Tevfik calls Xiang with the decision of where and when to eat • Maybe Jianwen also calls Xiang at the same time with a different decision. But the phone is busy. • Jianwen keeps calling. But Xiang is not going to answer because according to the protocol the next thing Xiang has to do is to call Jianwen. • Xiang calls Jianwen and passes the information
FCD Protocol: Tevfik’s Behavior Let’s look at all possible behaviors of Tevfik based on the FCD protocol Tevfik is hungry Tevfik receives a call from Jianwen passing him the lunch decision Tevfik calls Jianwen with the lunch decision Tevfik receives a call from Xiang passing him the lunch decision Tevfik calls Xiang with the lunch decision Tevfik receives a call from Xiang telling him the lunch decision that Tevfik has to pass to Jianwen
FCD Protocol: Tevfik’s Behavior T->J:D Message Labels: Tevfik calls Jianwen with the lunch decision !send ?receive J->X:P Jianwen calls Xiang to pass the decision !T->J:D ?J->T:P ?X->T:P !T->X:D ?X->T:D ?J->T:D !T->X:P !T->J:P
State machines for the FCD Protocol • Three state machines characterizing the behaviors of Tevfik, Xiang and Jianwen according to the FCD protocol Tevfik Xiang Jianwen ?J->X:P !J->T:D !X->J:D ?T->J:P !T->J:D ?J->T:P ?X->J:P !X->T:D ?T->X:P !T->J:D !J->X:D ?X->T:P ?T->X:D ?X->T:D ?J->X:D ?J->T:D ?X->J:D ?T->J:D !X->J:P !X->T:P !T->J:P !J->X:P !J->T:P !T->X:P
FCD Protocol Has Voicemail Problems • When the university installed a voicemail system FCD protocol started causing problems • We were showing up at different restaurants at different times! • Example scenario: • Tevfik calls Xiang with the lunch decision • Jianwen also calls Xiang with the lunch decision • The phone is busy (Xiang is talking to Tevfik) so Jianwen leaves a message • Xiang calls Jianwen passing the lunch decision • Jianwen does not answer (he already left for lunch) so Xiang leaves a message • Jianwen shows up at a different restaurant! • Message sequence is: T->X:D J->X:D X->J:P • The messages J->X:D andX->J:P are never consumed • This scenario is not possible without voicemail!
A Different Lunch Protocol • To fix this problem, Jianwen suggested that we change our lunch protocol as follows: • As the most senior researcher among us Jianwen would make the first call to either Xiang or Tevfik and tell when and where we would meet for lunch. • Then, the receiver of this call would pass the information to the other peer. • Let’s call this protocol the Jianwen Decides (JD) protocol
State machines for the JD Protocol • JD protocol works fine with voicemail! Xiang Jianwen Tevfik ?T->X:P ?X->T:P ?J->X:D ?J->T:D !J->T:D !J->X:D !T->X:P !X->T:P
Conversations • The FCD and JD protocols specify a set of conversations • A conversation is the sequence of messages generated during an execution of the protocol • We can specify the set of conversations without showing how the peers implement them • we call such a specification a conversation protocol
FCD and JD Conversation Protocols JD Protocol FCD Protocol T->X:D J->X:D J->T:D J->X:D X->J:D X->T:D T->J:D J->T:D J->X:P X->T:P T->J:P J->T:P X->T:P T->X:P T->X:P X->J:P Conversation set: { T->X:D X->J:P, T->J:DJ->X:P, X->T:DT->J:P, X->J:DJ->T:P, J->T:DT->X:P, J->X:D X->T:P } Conversation set: { J->T:DT->X:P, J->X:DX->T:P}
Observations & Questions • The implementation of the FCD protocol behaves differently with synchronous and asynchronous communication whereas the implementation of the JD protocol behaves the same. • Can we find a way to identify such implementations? • The implementation of the FCD protocol does not obey the FCD protocol if asynchronous communication is used whereas the implementation of the JD protocol obeys the JD protocol even if asynchronous communication used. • Given a conversation protocol can we figure out if there is an implementation which generates the same conversation set?
Conversations, Choreography, Orchestration • Peer state machines are orchestrations • A peer state machine can be specified using an orchestration language such as WS-BPEL • One can translate WS-BPEL specifications to peer state machines • A conversation protocol is a choreography specification • A conversation set corresponds to a choreography • A conversation set can be specified using a choreography language such as WS-CDL • One can translate WS-CDL specifications to conversation protocols
Bottom-Up vs. Top-Down Bottom-up approach • Specify the behavior of each peer • For example using an orchestration language such as WS-BPEL • The global communication behavior (conversation set) is implicitly defined based on the composed behavior of the peers • Global communication behavior is hard to understand and analyze Top-down approach • Specify the global communication behavior (conversation set) explicitly as a protocol • For example using a choreography language such as WS-CDL • Ensure that the conversations generated by the peers obey the protocol
Top-Down vs. Bottom-Up J->T:D J->X:D Conversation Protocol (Choreography Specification) LTL property ? GF(T->X(P) X->T(P)) T->X:P X->T:P Peer T Peer X Peer J Input Queue !J->T:D ?X->T:P ?T->X:P ?J->X:D ?J->T:D !J->X:D !T->X:P !X->T:P ... ? Virtual Watcher GF(T->X(P) X->T(P)) LTL property
Outline • Motivation • Composition of Web Services • Singularity Channel Contracts • Conversations • Realizability • Synchronizability • Applications • Recent Results
Realizability Question • Conversation protocol specifies the global communication behavior • How do we implement the peers? • How do we obtain the contracts that peers have to obey from the global contract specified by the conversation protocol? • Synthesize peer implementations by projecting the global protocol to each peer by dropping unrelated messages for each peer If this equality holds the conversation protocol is realizable • The JD protocol is realizable • The FCD protocol is not realizable Are there conditions which ensure the equivalence? ? Conversations specified by the conversation protocol Conversations generated by the projected services
Realizability Problem !m2 ?m2 ?m1 !m1 Peer A Peer B Peer C Peer D Projection of the conversation protocol to the peers • Not all conversation protocols are realizable! AB: m1 CD: m2 Conversation protocol Conversation “m2 m1” will also be generated by all peer implementations which follow the protocol
Realizability Conditions Three sufficient conditions for realizability (no message content) • Lossless join • Conversation set should be equivalent to the join of its projections to each peer • Synchronous compatible • When the projections are composed synchronously, there should not be a state where a peer is ready to send a message while the corresponding receiver is not ready to receive • Autonomous • At any state, each peer should be able to do only one of the following: send, receive or terminate (a peer can still choose among multiple messages)
Realizability Conditions • Following protocols fail one of the three conditions but satisfy the other two BA:m2 AB:m1 AB: m1 AB: m1 BA:m2 AB:m1 CD: m2 CA: m2 AC:m3 Not lossless join Not synchronous compatible Not autonomous
Outline • Motivation • Composition of Web Services • Singularity Channel Contracts • Conversations • Realizability • Synchronizability • Some Experiments • Applications
Bottom-Up Approach • We know that analyzing conversations of composite web services is difficult due to asynchronous communication • Model checking for conversation properties is undecidable even for finite state peers • The question is: • Can we identify the composite web services where asynchronous communication does not create a problem? • We call such compositions synchronizable • The implementation of the JD protocol is synchronizable • The implementation of the FCD protocol is not synchronizable
Three Examples, Example 1 • Conversation set is regular: (r1a1 | r2a2)* e • During all executions the message queues are bounded !a1 !a2 r1, r2 !e e ?r1 ?r2 ?a1 ?a2 ?e a1, a2 !r1 !r2 requester server
Example 2 • Conversation set is not regular • Queues are not bounded !a1 !a2 r1, r2 !e ?a1 ?a2 e ?r1 ?r2 ?e !r1 !r2 a1, a2 requester server
Example 3 r1, r2 !e !r1 !r2 ?r !a e ?r1 ?r2 ?a !r a1, a2 ?e requester server • Conversation set is regular: (r1 | r2 | ra)* e • Queues are not bounded
State Spaces of the Three Examples # of states in thousands queue length • Verification of Examples 2 and 3 are difficult even if we bound the queue length • How can we distinguish Examples 1 and 3 (with regular conversation sets) from 2? • Synchronizability Analysis
Synchronizability Analysis • A composite web service issynchronizable if its conversation setdoes not change • when asynchronous communication is replaced with synchronous communication • If a composite web service is synchronizable we can check the properties about its conversations using synchronous communication semantics • For finite state peers this is a finite state model checking problem
Synchronizability Analysis Sufficient conditions for synchronizability: • A composite web service is synchronizable, if it satisfies the synchronous compatible and autonomousconditions • Connection between realizability and synchronizability: • A conversation protocol is realizable if its projections to peers are synchronizable and the protocol itself satisfies the lossless join condition
Outline • Motivation • Composition of Web Services • Singularity Channel Contracts • Conversations • Realizability • Synchronizability • Applications • Recent Results
Singularity Channel Contract Verification • State machine construction allows for automated verification and analysis of channel communication • Singularity compiler automatically checks compliance of client and server processes to the specified contract • Claim from Singularity documentation: • "clients and servers that have been verified separately against the same contract C are guaranteed not to deadlock when allowed to communicate according to C.“ • This claim is wrong!
Deadlock Example: The TpmContract Server Projection Conversation Server Receive Queue Send? AckStartSend! SendComplete! TpmStatus! TpmStatus! GetTpmStatus? GetTpmStatus? ClientProjection ReadyState$0 ReadyState$0 Client Receive Queue CS:Send SC:AckStartSend Send! AckStartSend? SendComplete? SC:SendComplete ReadyState ReadyState IO_RUNNING IO_RUNNING SC:TpmStatus SC:TpmStatus TpmStatus? TpmStatus? CS:GetTpmStatus CS:GetTpmStatus GetTpmStatus! GetTpmStatus! ReadyState$1 ReadyState$1 IO_RUNNING$0 IO_RUNNING$0
Deadlock Example: The TpmContract Server Projection ReadyState$0 Conversation Server Receive Queue Send? AckStartSend! CS: Send SC: AckStartSend SC: SendComplete CS: GetTpmStatus SC: TpmStatus SendComplete! Send GetTpmStatus ReadyState IO_RUNNING TpmStatus! TpmStatus! GetTpmStatus? GetTpmStatus? ReadyState$1 IO_RUNNING$0 ClientProjection ReadyState$0 Client Receive Queue Send! AckStartSend? SendComplete? SendComplete AckStartSend ReadyState IO_RUNNING TpmStatus TpmStatus? TpmStatus? GetTpmStatus! GetTpmStatus! ReadyState$1 IO_RUNNING$0
Realizability Problem • KeyboardDeviceContract is not realizable • It violates the autonomous condition • It turns out that autonomous condition is sufficient (but not necessary) for realizability of two-party protocols (Singularity channel contracts are two-party protocols) • If a contract is autonomous, it is guaranteed to be realizable • However, it can be realizable but not autonomous • i.e., false positives are possible when we use autonomous condition as our realizability check
Autonomous condition and false positives • Example: TpmContract Fixed Violates Autonomous condition ReadyState$0 CS:Send SC:AckStartSend SC:SendComplete ReadyState IO_RUNNING SC:TpmStatus SC:TpmStatus CS:GetTpmStatus CS:GetTpmStatus ReadyState$1 IO_RUNNING$0 SC:TpmStatus SC:SendComplete IO_RUNNING$1
Model checking efficiency • Explicit state verification is expensive using asynchronous communication • Exponential state space explosion in the worst case • Example: BlowupKContract S1 SC:m1 SC:m2 S2 SC:m1 SC:m2 … SC:m1 SC:m2 Sk CS:m3
Model checking efficiency • If contract is realizable, conversations generated using asynchronous communication and synchronous communication are the same • Therefore, synchronous communication model can be used for verification S1 SC:m1 SC:m2 S2 SC:m1 SC:m2 … SC:m1 SC:m2 Sk CS:m3
Tune: A Tool For Analyzing Sing# Contracts Consumed by Produces File ContractParser Contract StateMachine Tune Component LTL Formulas LTL Formulas Report Sync Promela Async Promela Channel Contract External Tool ContractAnalyzer Synchronous Promela Generator Asynchronous Promela Generator Yes No Realizable? Spin Data Collector