1 | \documentclass[a4paper,10pt]{article} |
---|
2 | \usepackage[utf8]{inputenc} |
---|
3 | |
---|
4 | %opening |
---|
5 | \title{Fast Regular Expression Matching using Parallel Bitstreams} |
---|
6 | \author{ |
---|
7 | {Robert D. Cameron} \\ |
---|
8 | \and |
---|
9 | {Kenneth S. Herdy} \\ |
---|
10 | \and |
---|
11 | {Ben Hull} \\ |
---|
12 | \and |
---|
13 | {Thomas C. Shermer} \\ |
---|
14 | \\School of Computing Science |
---|
15 | \\Simon Fraser University |
---|
16 | } |
---|
17 | \begin{document} |
---|
18 | |
---|
19 | \date{} |
---|
20 | \maketitle |
---|
21 | |
---|
22 | \begin{abstract} |
---|
23 | |
---|
24 | A parallel regular expression matching method is introduced and studied in |
---|
25 | comparison with software tools designed for efficient on-line text searching such |
---|
26 | as the {\em grep} family. |
---|
27 | |
---|
28 | The method is based on the concept of bit-parallel data streams, |
---|
29 | in which parallel streams of bits are formed such |
---|
30 | that each stream comprises bits in one-to-one correspondence with the |
---|
31 | character code units of a source data stream. |
---|
32 | |
---|
33 | An implementation of the method in the form of a regular expression |
---|
34 | compiler is discussed. The compiler accepts a regular expression and produces |
---|
35 | sequences of arbitrary-length bit-parallel equations. |
---|
36 | Bit-parallel equations are then transformed |
---|
37 | into a low-level C-based implementation. |
---|
38 | |
---|
39 | The C-based program accepts the text to be searched and |
---|
40 | signals a match each time the text |
---|
41 | matches the compiled regular expression. |
---|
42 | |
---|
43 | |
---|
44 | These low-level implementations take advantage of |
---|
45 | the SIMD (single-instruction multiple-data) capabilities of commodity |
---|
46 | processors to yield a dramatic speed-up over |
---|
47 | traditional byte-at-a-time approaches. |
---|
48 | |
---|
49 | On processors supporting W-bit |
---|
50 | addition operations, the method processes W source characters |
---|
51 | in parallel and performs up to W finite state transitions per clock cycle. |
---|
52 | |
---|
53 | Additional parallelism is achieved through the introduction a new parallel |
---|
54 | scanning primitive termed {\em Match Star}. % which eliminates backtracking in Kleene Closure. |
---|
55 | |
---|
56 | |
---|
57 | We demonstrate the features and efficiency of our bit-parallel pattern |
---|
58 | matching appoach by searching text data sets for lines matching a regular expression. |
---|
59 | |
---|
60 | We evaluate the performance of our method against the widely known grep implemenations, |
---|
61 | {\em Gnu grep}, {\em agrep}, {\em nr-grep}, as well as {\em Google's re2} regular expression engine. |
---|
62 | |
---|
63 | Performance results show a dramatic speed-up over the traditional and state-of-the-art alternatives. |
---|
64 | |
---|
65 | |
---|
66 | \end{abstract} |
---|
67 | |
---|
68 | \section{Introduction} |
---|
69 | \label{Introduction} |
---|
70 | %\input{introduction.tex} |
---|
71 | |
---|
72 | Regular expresssion matching is an extensively studied problem with application to |
---|
73 | numerous application domains. A multitude |
---|
74 | of algorithms and software tools have been developed to the address the particular |
---|
75 | demands of the various application domains. |
---|
76 | |
---|
77 | The pattern matching problem can be |
---|
78 | stated as follows. Given a text T$_{1..n}$ of n characters and a pattern P, |
---|
79 | find all the text positions of T that start an occurrence of P. Alternatively, |
---|
80 | one may want all the final positions of occurrences. Some applications require |
---|
81 | slightly different output such as the line that matches the pattern. |
---|
82 | |
---|
83 | A pattern P can be a simple string, but it can also be, a regular expression. |
---|
84 | A regular expression, is an expression that specifies a set of strings. |
---|
85 | A regular expression is composed of (i) simple strings and (ii) the |
---|
86 | union, concatenation and Kleene closure of other regular expressions. |
---|
87 | To avoid parentheses it is assumed that the Kleene star has the highest priority, |
---|
88 | next concatenation and then alternation, however, most formalisms provides grouping |
---|
89 | operators to allow the definition of scope and operator precedence. |
---|
90 | Readers unfamiliar with the concept of regular expression matching are referred |
---|
91 | classical texts such as \cite{aho2007}. |
---|
92 | |
---|
93 | Regular expression matching is commonly performed using a wide variety of |
---|
94 | publically available software tools for on-line pattern matching. For instance, |
---|
95 | UNIX grep, Gnu grep, agrep, cgrep, nrgrep, and Perl regular |
---|
96 | expressions \cite{abou-assaleh2004}. Amongst these tools Gnu grep (egrep), |
---|
97 | agrep, and nrgrep are widely known and considered as |
---|
98 | the fastest regular expression matching tools in practice \cite{navarro2000}. |
---|
99 | and are of particular interest to this study. |
---|
100 | |
---|
101 | % simple patterns, extended patterns, regular expressions |
---|
102 | |
---|
103 | % motivation / previous work |
---|
104 | Although tradi finite state machine methods used in the scanning and parsing of |
---|
105 | text streams is considered to be the hardest of the â13 dwarvesâ to parallelize |
---|
106 | [1], parallel bitstream technology shows considerable promise for these types of |
---|
107 | applications [3, 4]. In this approach, character streams are processed W positions |
---|
108 | at a time using the W-bit SIMD registers commonly found on commodity processors |
---|
109 | (e.g., 128-bit XMM registers on Intel/AMD chips). This is achieved by |
---|
110 | first slicing the byte streams into eight separate basis bitstreams, one for each bit |
---|
111 | position within the byte. These basis bitstreams are then combined with bitwise |
---|
112 | logic and shifting operations to compute further parallel bit streams of interest. |
---|
113 | |
---|
114 | We further increase the parallelism in our methods by introducing a new parallel |
---|
115 | scanning primitive which we have coined Match Star. Match Star returns all matches |
---|
116 | in a single operation and eliminates backtracking |
---|
117 | when a partially successful search path fails. |
---|
118 | |
---|
119 | The remainder of this paper is organized as follows. |
---|
120 | Section~\ref{Background} presents background material on classic |
---|
121 | regular expression pattern matching techniques and provides insight into the |
---|
122 | efficiency of traditional regular expression software tools. Next, |
---|
123 | Section~\ref{Bit-parallel Data Streams} describes our parallel regular expression matching techniques. |
---|
124 | Section~\ref{Compiler Technology} presents our software toolchain for constructing pattern matching applications. |
---|
125 | Section~\ref{Methodology} describes the evaluation framework and Section~\ref{Experimental Results} |
---|
126 | presents a detailed performance analysis of our data parallel bitstream techniques against |
---|
127 | Gnu grep, agrep, and nr-grep. |
---|
128 | Section~\ref{Conclusion} concludes the paper. |
---|
129 | |
---|
130 | \section{Background} |
---|
131 | \label{Background} |
---|
132 | %\input{background.tex} |
---|
133 | |
---|
134 | The origins of regular expression matching date back to automata theory |
---|
135 | and formal language theory developed by Kleene in the 1950s \cite{kleene1951}. |
---|
136 | Thompson \cite{thompson1968} is credited with the first construction to convert regular expressions |
---|
137 | to nondeterministic finite automata (NFA) for regular expression matching. |
---|
138 | Following Thompson's approach, a regular expression of length m is first converted |
---|
139 | to an NFA with O(m) nodes. It is possible to search a text of length n using the |
---|
140 | NFA directly in O(mn) worst case time. Often, a more efficient choice |
---|
141 | is to convert the NFA into a DFA. A DFA has only a single active state and |
---|
142 | allows to search the text at O(n) worst-case optimal. It is well known that the |
---|
143 | conversion of the NFA to the DFA may result in the state explosion problem. |
---|
144 | That is the resultant DFA may have O($2^m$) states. |
---|
145 | |
---|
146 | Thompson's original work marked the beginning of a long line of |
---|
147 | regular expression implementations that |
---|
148 | process an input string, character-at-a-time, and that transition patterm matching state |
---|
149 | based on the current state and the next character read. |
---|
150 | |
---|
151 | |
---|
152 | Bit-parallel simulation of automata. |
---|
153 | |
---|
154 | The ideas presented up to now aim at a good implementation of the automa- |
---|
155 | ton, but they must inspect all the text characters. In many cases, however, the |
---|
156 | regular expression involves sets of relatively long substrings that must appear |
---|
157 | for the regular expression to match. |
---|
158 | |
---|
159 | |
---|
160 | Suffix automata (BDM/BNDM) |
---|
161 | |
---|
162 | Skip characters pattern length (occurence frequency and length). |
---|
163 | |
---|
164 | |
---|
165 | \section{Bit-parallel Data Streams} |
---|
166 | \label{Bit-parallel data streams} |
---|
167 | |
---|
168 | The advantage of the parallel bit stream representation is that we can |
---|
169 | use the 128-bit SIMD registers commonly found on commodity processors |
---|
170 | (e.g. SSE on Intel) to process 128 byte positions at a time using |
---|
171 | bitwise logic, shifting and other operations. |
---|
172 | |
---|
173 | Skip characters register width. |
---|
174 | |
---|
175 | \subsection{Software Tools} |
---|
176 | |
---|
177 | %Thompson created the first grep (UNIX grep) as a standalone adaptation |
---|
178 | %of the regular expression parser he had written for the UNIX ed utility. |
---|
179 | %In 1976, Aho improved upon Thompson's implementation that with a DFA-based implementation called egrep. |
---|
180 | %Egrep was faster then grep for simple patterns but for more complex searches it lagged behind because of the |
---|
181 | %time it took to build a complete finite automaton for the regular expression before it could even start searching. |
---|
182 | %Since grep used a nondeterministic finite automaton it took less time to build the state machine but more time |
---|
183 | %to evaluate strings with it. Aho later used a technique called cached lazy evaluation to improve the performance of egrep. |
---|
184 | %It took zero set-up time and just one additional test in the inner loop. |
---|
185 | %http://pages.cs.wisc.edu/~mdant/cs520_4.html |
---|
186 | |
---|
187 | \subsection{Mask Star} |
---|
188 | |
---|
189 | %Wikipedia |
---|
190 | Backtracking is a general algorithm for finding all solutions to some computational problem, |
---|
191 | that incrementally builds candidates to the solutions. |
---|
192 | |
---|
193 | \section{Compiler Technology} |
---|
194 | \label{Compiler Technology} |
---|
195 | |
---|
196 | \section{Methodology} |
---|
197 | \label{Methodology} |
---|
198 | %\input{methodology.tex} |
---|
199 | |
---|
200 | We compare the performance of our parallel \bitstream{} techniques against |
---|
201 | Gnu grep, agrep, and nr-grep. |
---|
202 | |
---|
203 | Given a regular expression R and a test T the regular expression matching |
---|
204 | problem finds all ending position of substrings in Q that matches a string in |
---|
205 | the language denoted by R. |
---|
206 | |
---|
207 | The behaviour of Gnu grep, agrep, and nr-grep are differ in that |
---|
208 | |
---|
209 | Gnu grep |
---|
210 | |
---|
211 | agrep |
---|
212 | |
---|
213 | nr-grep |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | \section{Experimental Results} |
---|
218 | \label{Experimental Results} |
---|
219 | %\input{results.tex} |
---|
220 | |
---|
221 | \section{Conclusion} |
---|
222 | \label{Conclusion} |
---|
223 | %\input{conclusion.tex} |
---|
224 | |
---|
225 | { |
---|
226 | \bibliographystyle{acm} |
---|
227 | \bibliography{reference} |
---|
228 | } |
---|
229 | |
---|
230 | \end{document} |
---|