11 Applying reactive programming everywhere with agents

 

This chapter covers

  • Using the message-passing concurrent model
  • Handling millions of messages per second
  • Using the agent programming model
  • Parallelizing a workflow and coordinating agents

Web applications play an important role in our lives, from large social networks and media streaming to online banking systems and collaborative online gaming. Certain websites now handle as much traffic as the entire internet did less than a decade ago. Facebook and Twitter, two of the most popular websites, have billions of users each. To ensure that these applications thrive, concurrent connections, scalability, and distributed systems are essential. Traditional architectures from years past cannot operate under this high volume of requests.

High-performance computing is becoming a necessity. The message-passing concurrent programming model is the answer to this demand, as evidenced by the increasing support for the message-passing model in mainstream languages such as Java, C#, and C++.

The number of concurrent online connections will certainly continue to grow. The trend is shifting to physical devices that are interconnected, generating sophisticated and massive networks constantly operating and exchanging messages. It’s predicted that the Internet of Things (IoT) will expand to an installed base of 75 billion units by 2025 (http://mng.bz/wiwP).

11.1 What’s reactive programming, and how is it useful?

11.2 The asynchronous message-passing programming model

11.2.1 Relation with message passing and immutability

11.2.2 Natural isolation

11.3 What is an agent?

11.3.1 The components of an agent

11.3.2 What an agent can do

11.3.3 The share-nothing approach for lock-free concurrent programming

11.3.4 How is agent-based programming functional?

11.3.5 Agent is object-oriented

11.4 The F# agent: MailboxProcessor

11.4.1 The mailbox asynchronous recursive loop

11.5 Avoiding database bottlenecks with F# MailboxProcessor

11.5.1 The MailboxProcessor message type: discriminated unions

11.5.2 MailboxProcessor two-way communication

11.5.3 Consuming the AgentSQL from C#

11.5.4 Parallelizing the workflow with group coordination of agents

11.5.5 How to handle errors with F# MailboxProcessor

11.5.6 Stopping MailboxProcessor agents—CancellationToken

11.5.7 Distributing the work with MailboxProcessor

11.5.8 Caching operations with an agent

11.5.9 Reporting results from a MailboxProcessor

11.5.10 Using the thread pool to report events from MailboxProcessor

11.6 F# MailboxProcessor: 10,000 agents for a game of life

Summary