• No results found

Understand the Java Sequential SearchStreamGang Case Study

N/A
N/A
Protected

Academic year: 2021

Share "Understand the Java Sequential SearchStreamGang Case Study"

Copied!
24
0
0

Loading.... (view fulltext now)

Full text

(1)

Understand the Java Sequential

SearchStreamGang Case Study

Douglas C. Schmidt

[email protected]

www.dre.vanderbilt.edu/~schmidt

Professor of Computer Science Institute for Software

Integrated Systems Vanderbilt University Nashville, Tennessee, USA

(2)

2

Learning Objectives in this Part of the Lesson

• Understand the design of the SearchStreamGang program

See github.com/douglascraigschmidt/LiveLessons/tree/master/SearchStreamGang map(phrase -> searchForPhrase(…)) filter(not(SearchResults::isEmpty)) collect(toList()) 45,000+ phrases Search Phrases stream()

(3)

3

Learning Objectives in this Part of the Lesson

• Understand the design of the SearchStreamGang program

This example is more interesting than the SimpleSearchStream program

map(phrase -> searchForPhrase(…)) filter(not(SearchResults::isEmpty)) collect(toList()) 45,000+ phrases Search Phrases stream()

(4)

4

Learning Objectives in this Part of the Lesson

• Understand the design of the SearchStreamGang program • Later we’ll cover the performance of

different implementation strategies

See github.com/douglascraigschmidt/LiveLessons/tree/master/SearchStreamGang

Starting SearchStreamGangTest

PARALLEL_SPLITERATOR executed in 409 msecs

COMPLETABLE_FUTURES_INPUTS executed in 426 msecs COMPLETABLE_FUTURES_PHASES executed in 427 msecs PARALLEL_STREAMS executed in 437 msecs

PARALLEL_STREAM_PHASES executed in 440 msecs RXJAVA_PHASES executed in 485 msecs

PARALLEL_STREAM_INPUTS executed in 802 msecs RXJAVA_INPUTS executed in 866 msecs

SEQUENTIAL_LOOPS executed in 1638 msecs SEQUENTIAL_STREAM executed in 1958 msecs Ending SearchStreamGangTest map(phrase -> searchForPhrase(…)) filter(not(SearchResults::isEmpty)) collect(toList()) 45,000+ phrases Search Phrases stream()

(5)

5

Overview of

(6)

6

See github.com/douglascraigschmidt/LiveLessons/tree/master/SearchTaskGang

• SearchStreamGang revises SearchTaskGang to use functional programming & streams instead of OO programming

Overview of SearchStreamGang

45,000+ phrases

"do", "re", "mi", "fa", "so", "la", "ti", "do"

Search Words Input Strings to Search

(7)

7

• SearchStreamGang revises SearchTaskGang to use functional programming & streams instead of OO programming

• SearchTaskGang showcases the Java executor framework for tasks that are “embarrassingly parallel”

Overview of SearchStreamGang

e.g., Executor, ExecutorService, ExecutorCompletionService

45,000+ phrases

"do", "re", "mi", "fa", "so", "la", "ti", "do"

Search Words Input Strings to Search

(8)

8

See github.com/douglascraigschmidt/LiveLessons/tree/master/SimpleSearchStream

• SearchStreamGang is also a more powerful revision of SimpleSearchStream

Overview of SearchStreamGang

map(word -> searchForWord(…))

filter(not(SearchResults::isEmpty))

collect(toList())

45,000+ phrases

"do", "re", "mi", "fa", "so", "la", "ti", "do"

Search Words Input String to Search

map(phrase -> searchForPhrase(…))

filter(not(SearchResults::isEmpty))

collect(toList())

45,000+ phrases

Search Phrases Input Strings to Search

(9)

9

• SearchStreamGang is also a more powerful revision of SimpleSearchStream, e.g. • It uses regular expressions to find

phrases in works of Shakespeare

Overview of SearchStreamGang

(10)

10

• SearchStreamGang is also a more powerful revision of SimpleSearchStream, e.g. • It uses regular expressions to find

phrases in works of Shakespeare

Overview of SearchStreamGang

A phrase can match anywhere within a line

“…

My liege, and madam, to expostulate What majesty should be, what duty is,

Why day is day, night is night, and time is time. Were nothing but to waste night, day, and time. Therefore, since brevity is the soul of wit,

And tediousness the limbs and outward flourishes, I will be brief. …”

(11)

11

• SearchStreamGang is also a more powerful revision of SimpleSearchStream, e.g. • It uses regular expressions to find

phrases in works of Shakespeare

Overview of SearchStreamGang

The phrases can also match across multiple lines

“…

What's in a name? That which we call a rose By any other name would smell as sweet.

So Romeo would, were he not Romeo call'd, Retain that dear perfection which he owes Without that title. …”

“What’s in a name? That which we call a rose By any other name would smell as sweet.”

(12)

12

e.g., parallel streams, parallel spliterator, fork-join pool, & completable futures • SearchStreamGang is also a more powerful revision of SimpleSearchStream, e.g.

• It uses regular expressions to find phrases in works of Shakespeare

• It defines a framework for apples-to-apples comparisons of Java’s parallelism strategies.

(13)

13

The differences in performance is quite informative! Starting SearchStreamGangTest

PARALLEL_SPLITERATOR executed in 409 msecs

COMPLETABLE_FUTURES_INPUTS executed in 426 msecs COMPLETABLE_FUTURES_PHASES executed in 427 msecs PARALLEL_STREAMS executed in 437 msecs

PARALLEL_STREAM_PHASES executed in 440 msecs RXJAVA_PHASES executed in 485 msecs

PARALLEL_STREAM_INPUTS executed in 802 msecs RXJAVA_INPUTS executed in 866 msecs

SEQUENTIAL_LOOPS executed in 1638 msecs SEQUENTIAL_STREAM executed in 1958 msecs Ending SearchStreamGangTest

• SearchStreamGang is also a more powerful revision of SimpleSearchStream, e.g.

• It uses regular expressions to find phrases in works of Shakespeare

• It defines a framework for apples-to-apples comparisons of Java’s parallelism strategies.

(14)

14

Overview of SearchStreamGang

• SearchStreamGang is also a more powerful revision of SimpleSearchStream, e.g.

• It uses regular expressions to find phrases in works of Shakespeare • It defines a framework for

apples-to-apples comparisons of Java’s parallelism strategies.

• We’ll cover the Java parallel strategies after first covering sequential streams.

(15)

15

Overview of SearchStreamGang

• SearchStreamGang is also a more powerful revision of SimpleSearchStream, e.g.

• It uses regular expressions to find phrases in works of Shakespeare • It defines a framework for

apples-to-apples comparisons of Java’s parallelism strategies.

• We’ll cover the Java parallel strategies after first covering sequential streams.

(16)

16

Applying Sequential Streams

to SearchStreamGang

(17)

17

• We show aggregate operations in the SearchStreamGang’s processStream() & processInput() methods

See github.com/douglascraigschmidt/LiveLessons/tree/master/SearchStreamGang

(18)

18

• We show aggregate operations in the SearchStreamGang’s processStream() & processInput() methods

Applying Sequential Streams to SearchStreamGang

return mPhrasesToFind .stream()

.map(phrase -> searchForPhrase(phrase, input, title, false)) .filter(not(SearchResults::isEmpty) .collect(toList()); getInput() .stream() .map(this::processInput) .collect(toList()); See livelessons/streamgangs/SearchWithSequentialStreams.java

(19)

19

• We show aggregate operations in the SearchStreamGang’s processStream() & processInput() methods

i.e., the map(), filter(), & collect() aggregate operations

Applying Sequential Streams to SearchStreamGang

return mPhrasesToFind .stream()

.map(phrase -> searchForPhrase(phrase, input, title, false)) .filter(not(SearchResults::isEmpty) .collect(toList()); getInput() .stream() .map(this::processInput) .collect(toList());

(20)

20

• We show aggregate operations in the SearchStreamGang’s processStream() & processInput() methods

• processStream()

• Uses a sequential stream to search a list of input strings in one thread

Applying Sequential Streams to SearchStreamGang

stream()

map(this::processInput)

collect(toList())

45,000+ phrases

Search Phrases Input Strings to Search

Each input string contains a work of Shakespeare (e.g., Hamlet, MacBeth, etc.)

(21)

21

• We show aggregate operations in the SearchStreamGang’s processStream() & processInput() methods

• processStream()

• Uses a sequential stream to search a list of input strings in one thread

Applying Sequential Streams to SearchStreamGang

stream()

map(this::processInput)

collect(toList())

45,000+ phrases

Search Phrases Input Strings to Search

(22)

22

Search Phrases

• We show aggregate operations in the SearchStreamGang’s processStream() & processInput() methods

• processStream()

• processInput()

• Uses a sequential stream to search a given input string & locate all the occurrences of phases in one thread

Applying Sequential Streams to SearchStreamGang

stream()

map(phrase -> searchForPhrase(…)

filter(not(SearchResults::isEmpty))

45,000+ phrases

Input Strings to Search

(23)

23

Search Phrases

• We show aggregate operations in the SearchStreamGang’s processStream() & processInput() methods

• processStream()

• processInput()

• Uses a sequential stream to search a given input string & locate all the occurrences of phases in one thread

Applying Sequential Streams to SearchStreamGang

stream()

map(phrase -> searchForPhrase(…)

filter(not(SearchResults::isEmpty))

45,000+ phrases

Input Strings to Search

collect(toList())

(24)

24

End of Understand the Java

Sequential SearchStreamGang

References

Related documents

This Committee set direction and supported efforts to improve the flow of information and materials to the craft workers. It also helped selected subcontractors:.. 1)

Among the 15 weed species tested, the leaf litter leachate of Centrosema pubescens was observed to be the most sensitive plant material inhibiting the growth of lettuce radicle

Cut-and-cover construction of the extension of the 63rd Street Tunnel, Queens, New York: Tiebacks (steel bars or cables) are angled into the completed slurry walls and anchored

Although the ma­ jority of OECD countries have engaged in some institutional reforms, the empirical evidence of their impact on efficiency is so far limited due to:

The book Barometer Maatschappelijk Vastgoed: onderzoeken perspectieven op maatschappelijk en financieel rendement (Social Real Estate Barometer: researching perspectives on

At the option of the Lender, and without necessity of any demand upon or notice to the Borrower all of which are hereby expressly waived by the Borrower and

Aurora can share your content to multiple locations Aurora shares to multiple locations Aurora shares to multiple locations Aurora shares to multiple

- options, futures, swaps, forward rate agreements and any other derivative contracts relating to securities, currencies, interest rates or yields, or other