Getting Started with Apache Flink

Source: Internet
Author: User
Tags apache flink


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.