Table of Contents
About The Project
FIO is a type-safe, highly concurrent and asynchronous library for F# that is based on principles from pure functional programming. It provides a construct known as the IO monad for handling expressions with side effects. It uses the concept of "green threads" also known as "fibers" to provide scalable and efficient concurrency.
FIO is an attempt at creating a similar environment to that of ZIO for Scala. FIO is both inspired by ZIO and Cats Effect.
DISCLAIMER: FIO is in early development stages and a lot of improvements and enhancements can be made. This README might be lackluster.
Built With
FIO is built using the following technologies:
Getting Started
It is easy to get started with FIO.
Prerequisites
- Download and install .NET 6.0
- Download and install a compatible IDE such as Visual Studio or Rider
Installation
- Download or clone this repository
- Open it in your IDE of choice
- Navigate to the Examples project and check out the example programs or create a new file to start using FIO
Usage
Create a new class and import the library using "open FSharp.FIO". For example:
open FSharp.FIO
[<EntryPoint>]
let main _ =
let askForName =
fio (fun () -> printfn "%s" "Hello! What is your name?")
>> fun _ ->
fio (fun () -> Console.ReadLine())
>> fun name ->
fio (fun () -> printfn $"Hello, %s{name}, welcome to FIO!")
let fiber = Advanced.Runtime().Run askForName
let result = fiber.Await()
printfn $"%A{result}"
Benchmarks
This repository contains five benchmarks that each tests an aspect of concurrent computing. All benchmarks reside from the Savina - An Actor Benchmark Suite paper.
- Pingpong (Message sending and retrieval)
- ThreadRing (Message sending and retrieval, context switching between fibers)
- Big (Contention on channel, many-to-many message passing)
- Bang (Many-to-one messaging)
- Spawn (Spawning time of fibers)
The benchmarks can be through the following command line options:
OPTIONS:
--naive-runtime specify naive runtime. (specify only one runtime)
--intermediate-runtime <evalworkercount> <blockingworkercount> <evalstepcount>
specify eval worker count, blocking worker count and eval step count for intermediate
runtime. (specify only one runtime)
--advanced-runtime <evalworkercount> <blockingworkercount> <evalstepcount>
specify eval worker count, blocking worker count and eval step count for advanced runtime.
(specify only one runtime)
--deadlocking-runtime <evalworkercount> <blockingworkercount> <evalstepcount>
specify eval worker count, blocking worker count and eval step count for deadlocking
runtime. (specify only one runtime)
--runs <runs> specify the number of runs for each benchmark.
--process-increment <processcountinc> <inctimes>
specify the value of process count increment and how many times.
--pingpong <roundcount>
specify round count for pingpong benchmark.
--threadring <processcount> <roundcount>
specify process count and round count for threadring benchmark.
--big <processcount> <roundcount>
specify process count and round count for big benchmark.
--bang <processcount> <roundcount>
specify process count and round count for bang benchmark.
--spawn <processcount>
specify process count for spawn benchmark.
--help display this list of options. display this list of options.
For example, running 30 runs of each benchmark using the advanced runtime with 7 evaluation workers, 1 blocking worker and 15 evaluation steps would look as so:
--advanced-runtime 7 1 15 --runs 30 --pingpong 120000 --threadring 2000 1 --big 500 1 --bang 3000 1 --spawn 3000
Additionally, the FIO project supports two conditional compilation options:
- DETECT_DEADLOCK: Enables a naive deadlock detecting thread that attempts to detect if a deadlock has occurred when running FIO programs
- MONITOR: Enables a monitoring thread that prints out data structure content during when running FIO programs
Performance
Below the scalability of each interpreter can be seen for each benchmark. I is denoting the intermediate runtime and A the advanced. To give some insight into the interpreters, the naive interpreter uses operating system threads, the intermediate uses fibers with handling of blocked FIO programs in linear time, and the advanced uses fibers with constant time handling.
- Threadring
- Big
- Bang
- Spawn
License
Distributed under the GNU General Public License v3.0. See LICENSE.md for more information.
Contact
Daniel Larsen (iyyel) - iyyel.io - mail@iyyel.io