Coder Social home page Coder Social logo

bekisz / flink-pi Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 51 KB

Simple Flink example to use Flink DataStream and SQL APIs for solving the same and simple problem. Estimating the value Pi more and more precisely via Monte-Carlo trials.

License: Apache License 2.0

Scala 100.00%
flink flink-examples flink-example flink-sql flink-streaming blink

flink-pi's Introduction

flink-pi

Simple Scala examples for using Apache Flink's DataStream and SQL API for the same problem, that is simple enough not to involve other libraries.

The example approximates Pi with the Monte Carlo method using Flink's

All three examples have the same functionality, by iteratively approaching better and better estimate for the value of Pi. All write the actual best estimate in the given intervals (3 sec)
till an explicit user interruption.

How it Works

As a continuous DataSource, (random/sequnetial) IDs are generated either by IdGenerator or by DataGen SQL Connector.

The next step is the creation is random point in a 2x2 box , centered in the origin, for each generated ID. The ratio of withinCircle points in the sample estimates Pi/4. Rationale : The area of the 2x2 box is 4, the area of the 1 unit radius circle inside is 1*1*Pi = Pi by definition. As a consequence, the ratio of these two areas are : Pi/4 = P(isWithinCircle)/1=> Pi = 4 * P(isWithinCircle) The data from the millions of trials (resulting 4.0's and 0.0's) are aggregated in two phases. The first phase is on each thread (the bulk of the workload), while the second is a global aggregation.

The output is collected in Print SQL Sink or Flink's DataStreamSink.

flink-pi's People

Contributors

bekisz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.