From 44efac4f5ba50439cc6df6a2b25a6ca0e96df0d5 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 6 Jul 2011 19:21:20 +0200 Subject: [PATCH] callagent: Big performance improvement, cache the parser Constructing a PetitParser is an expensive operation (Object>>becomeForward:) we can keep the parser in the class. For the SIPTransactions we keep it as a global, it is assumed that all SIPTransactions operate through the same process and will not run into concurrency issues. --- callagent/SIPCallAgent.st | 9 +++++++-- callagent/SIPTransactions.st | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/callagent/SIPCallAgent.st b/callagent/SIPCallAgent.st index a0b7255..de4d420 100644 --- a/callagent/SIPCallAgent.st +++ b/callagent/SIPCallAgent.st @@ -208,7 +208,7 @@ Object subclass: SIPUserAgentBase [ ] SIPUserAgentBase subclass: SIPUserAgent [ - | transactions retransmit sem | + | dialogs transactions retransmit sem parser | @@ -274,13 +274,18 @@ SIPUserAgentBase subclass: SIPUserAgent [ OsmoDispatcher dispatchBlock: [self transportDataInternal: aData]. ] + parser [ + + ^ parser ifNil: [parser := SIPParser new] + ] + transportDataInternal: aData [ | req data | [ data := aData data copyFrom: 1 to: aData size. - req := SIPParser parse: data asString onError: [:e | + req := self parser parse: data asString onError: [:e | data printNl. self logError: 'Failed to parse: "%1" with %2' % {data asString. e} area: #sip. diff --git a/callagent/SIPTransactions.st b/callagent/SIPTransactions.st index 344c609..e7c39cc 100644 --- a/callagent/SIPTransactions.st +++ b/callagent/SIPTransactions.st @@ -31,6 +31,8 @@ Object subclass: SIPTransaction [ SIPTransaction class >> stateTerminated [ ^ #terminated ] SIPTransaction class >> stateCanceled [ ^ #canceled ] + Grammar := nil. + SIPTransaction class >> createWith: aDialog on: aUA cseq: aCseq [ ^ self new @@ -41,6 +43,20 @@ Object subclass: SIPTransaction [ yourself. ] + SIPTransaction class >> grammar [ + + ^ Grammar ifNil: [Grammar := SIPGrammar new] + ] + + SIPTransaction class >> verifyGrammar: aData [ + + self grammar parse: aData onError: [:e | + e logException: 'Outgoing data has parsing error' area: #sip. + e signal + ] + ] + + initialize [ sem := RecursionLock new. @@ -103,7 +119,7 @@ Object subclass: SIPTransaction [ "validate the output" - res := SIPGrammar parse: aData. + self class verifyGrammar: aData. datagram := Sockets.Datagram data: aData