The configuration environment includes JAVA_HOMEjobmanager.rpc.address JOBMANAGER.HEAP.MB and Taskmanager.heap.mbtaskmanager.numberOfTaskSlotstaskmanager.tmp.dirsslaves file
Start off
bin/start-cluster.sh
bin/stop-cluster.sh
Preliminary Use Public Static voidMain (string[] args)throwsException {if(Args.length! = 2) {System.err.println ("Usage:\nsockettextstreamwordcount ); return; } String hostName= Args[0]; Integer Port= Integer.parseint (args[1]); //set up the execution environment FinalStreamexecutionenvironment env =streamexecutionenvironment. getexecutionenvironment (); //Get input datadatastream<string> Text =Env.sockettextstream (HostName, Port); DataStream<tuple2<string, integer>> counts =//split up the lines in pairs (2-tuples) containing: (word,1)Text.flatmap (Newlinesplitter ())//GROUP by the tuple field ' 0 ' and sum up tuple field ' 1 '. keyby (0). SUM (1); Counts.print (); //Execute ProgramEnv.execute ("WordCount from Sockettextstream Example"); } Public Static Final classLinesplitterImplementsFlatmapfunction<string, Tuple2<string, integer>>{@Override Public voidFlatMap (String value, collector<tuple2<string, integer>>Out ) { //normalize and split the linestring[] tokens = Value.tolowercase (). Split ("\\w+"); //Emit the pairs for(String token:tokens) {if(Token.length () > 0) {Out.collect (NewTuple2<string, integer> (token, 1)); } } } }
programming steps, and spark very similar obtain an execution environment,load/ This data,specify where to put the Results of your Computations,trigger the program execution
int& Counters The steps for summing and counting include defining, adding to context, manipulating, and finally getting the privatenew intcounter ( ); Getruntimecontext (). Addaccumulator (this. numlines); this. Numlines.add (1); Myjobexecutionresult=env.execute ("xxx"); Myjobexecutionresult.getaccumulatorresult ("Num-lines")
The concurrency number is set by the system level:parallelism. default=10Client level:. /bin/flink run-ptrue); Execution Environment Level:env.setParallelism (3); Operator level:datastream<tuple2<string, integer>> wordcounts = text . FlatMap (new linesplitter ()) . Keyby (0 ) . TimeWindow (Time.seconds (5)). sum (1). setparallelism (5);
Final framing and execution flowchart that looks similar to spark
Getting Started with Apache Flink