Modern Systems Programming with Scala Native

Book description

Access the power of bare-metal systems programming with Scala Native, an ahead-of-time Scala compiler. Without the baggage of legacy frameworks and virtual machines, Scala Native lets you re-imagine how your programs interact with your operating system. Compile Scala code down to native machine instructions; seamlessly invoke operating system APIs for low-level networking and IO; control pointers, arrays, and other memory management techniques for extreme performance; and enjoy instant start-up times. Skip the JVM and improve your code performance by getting close to the metal.

Developers generally build systems on top of the work of those who came before, accumulating layer upon layer of abstraction. Scala Native provides a rare opportunity to remove layers. Without the JVM, Scala Native uses POSIX and ANSI C APIs to build concise, expressive programs that run unusually close to bare metal. Scala Native compiles Scala code down to native machine instructions instead of JVM bytecode. It starts up fast, without the sluggish warm-up phase that's common for just-in-time compilers. Scala Native programs can seamlessly invoke operating system APIs for low-level networking and IO. And Scala Native lets you control pointers, arrays, and other memory layout types for extreme performance.

Write practical, bare-metal code with Scala Native, step by step. Understand the foundations of systems programming, including pointers, arrays, strings, and memory management. Use the UNIX socket API to write network client and server programs without the sort of frameworks higher-level languages rely on. Put all the pieces together to design and implement a modern, asynchronous microservice-style HTTP framework from scratch.

Take advantage of Scala Native's clean, modern syntax to write lean, high-performance code without the JVM.

What You Need:

A modern Windows, Mac OS, or Linux system capable of running Docker. All code examples in the book are designed to run on a portable Docker-based build environment that runs anywhere. If you don't have Docker yet, see the Appendix for instructions on how to get it.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgments
  2.  Foreword
  3.  Preface
    1. Who This Book Is For
    2. What’s In This Book
    3. Working with the Code
    4. Online Resources
  4.  Systems Programming in the Twenty-First Century
    1. What Is Systems Programming?
    2. Moving Toward Modern Systems Programming
    3. Why Scala Native?
    4. What Makes Scala Native Different
  5. Part I. Foundations of Systems Programming
    1. 1. The Basics: Input and Output
      1. Working with Output
      2. Working with Input
      3. Case Study: Google NGrams
      4. What’s Next
    2. 2. Arrays, Structs, and the Heap
      1. The Stack and the Heap
      2. Structs, Arrays, and Sorting
      3. Sorting an Array
      4. Aggregation at Scale
      5. What’s Next
    3. 3. Writing a Simple HTTP Client
      1. Defining Terms
      2. Working with TCP
      3. Making a TCP Connection
      4. Testing Network Code with Netcat
      5. Introducing HTTP
      6. Implementing HTTP
      7. Testing Our Code
      8. What’s Next
    4. 4. Managing Processes: A Deconstructed Shell
      1. Running a Program
      2. Introducing exec
      3. What Went Wrong?
      4. Introducing Concurrency with fork() and wait()
      5. Supervising Multiple Processes
      6. Working with Pipes
      7. What’s Next
    5. 5. Writing a Server the Old-Fashioned Way
      1. Understanding How a Server Works
      2. Building Our Server
      3. Creating a Minimum Viable Server
      4. Handling HTTP
      5. Performance Testing with Gatling
      6. What’s Next
  6. Part II. Modern Systems Programming
    1. 6. Doing I/O Right, with Event Loops
      1. Blocking and Polling
      2. Introducing libuv
      3. Working with Asynchronous TCP Sockets
      4. Building an Asynchronous HTTP Server
      5. What’s Next
    2. 7. Functions and Futures: Patterns for Distributed Services
      1. Designing an Asynchronous API
      2. Introducing Futures
      3. Implementing Futures
      4. Implementing an ExecutionContext
      5. Futures and Promises
      6. Introducing libcurl
      7. Asynchronous curl
      8. What’s Next
    3. 8. Streaming with Pipes and Files
      1. Looking at Streams, Files, and Descriptors
      2. Streaming Pipe Input in libuv
      3. Streaming File Input in libuv
      4. Streaming File Output in libuv
      5. Stream Processors
      6. What’s Next
    4. 9. Durability: An Embedded Key-Value Database with LMDB
      1. Introducing Embedded Storage
      2. Defining LMDB Concepts
      3. Working with the LMDB API
      4. Serialization and Deserialization with JSON
      5. Putting LMDB on the Web
      6. What’s Next
    5. 10. Services: Encapsulation and Abstraction for Modern Designs
      1. Services and Distributed Systems
      2. Parsing, Revisited
      3. Moving from Server to Service
      4. Implementing an Idiomatic Service DSL
      5. Integrations and Ecosystems
      6. The Way Forward
  7. A1. Setting Up the Environment
    1. Running Scala Native on Mac OS
    2. Why Use Containers?
    3. Installing and Configuring Docker
    4. Running Scala Native in Docker

Product information

  • Title: Modern Systems Programming with Scala Native
  • Author(s): Richard Whaling
  • Release date: January 2020
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680506228