Easier Microservices With Async C++ Frameworks? You Heard It Right!

Facebook
Twitter
LinkedIn

A real-life example can easily explain asynchronous C++ programming: Imagine you have an interview, and after you are done, HR tells you that you do not need to call back; they would contact you themselves. 

For many C++ developers, a structural framework is like a human resource recruiter. Instead of letting the programmer drive the flow of control for the whole application, the framework controls the environment and invokes callbacks or event handlers provided by the programmer.

 

Async C++ Framework

This paradigm lets you decouple the start of the asynchronous operation from its completion in asynchronous systems. The programmer initiates the operation and then registers a callback that will be invoked when the results are available. Not having to wait for completion means you can do practical work while the operation is in progress — service the message loop or start other asynchronous operations, for example. The “frosted window,” the “spinning donut,” and other such phenomena will become relics of the past if you follow this pattern rigorously for all potentially blocking operations. Your apps will become fast and fluid.

C++ developers can get an assist in building asynchronous microservices with a new open source framework intended to solve the problem of efficient I/O interactions.

According to the project’s GitHub repo, Userver, the asynchronous framework offers a set of abstractions for the “fast and comfortable” creation of C++ microservices, services, and utilities. The project is currently in beta.

 

Supported Platforms for Async C++

The only requirement to use Async++ is a C++11 compiler and standard library. Unfortunately, C++11 is not yet fully implemented on most platforms. Here is the list of OS and compiler combinations are known to work.

  • Linux: Works with GCC 4.7+, Clang 3.2+, and Intel compiler 15+.
  • Mac: Works with Apple Clang (using libc++). GCC also works, but you must get a recent version (4.7+).
  • iOS: Works with Apple Clang (using libc++). Note: because iOS has no thread local support, the library uses a workaround based on pthreads.
  • Windows: Works with GCC 4.8+ (with pthread-win32) and Visual Studio 2013+.

 

Documentation of Async C++ Framework

The Async++ documentation is split into four parts:

  • Tasks: This describes task objects which are the core Async++. Reading this first is strongly recommended.
  • Parallel algorithms: This describes functions to run work on ranges in parallel.
  • Schedulers: This describes the low-level details of Async++ and how to customize it.
  • API Reference: This gives detailed descriptions of all the classes and functions available in Async++.

 

Userver

Userver promises to solve the issue of efficient I/O transactions transparently for developers. The developers behind the framework say it offers the speed of C++,  the simplicity of Python, and the coroutine model of Go. With Userver, operations that usually suspend the thread of execution do not do so; instead, the line processes other tasks and returns to the handling of the operation only when it is guaranteed to execute immediately.

Developers get short source code and avoid CPU-consuming context switches from the OS while efficiently utilizing the CPU with a small number of execution threads, the project states. Other features of the Userver framework include:

Components for Userver

A set of high-level components for caches, distributed locking, JSON/YAML/BSON, logging, metrics, statistics, and tasks.

  • The ability to perform on-the-fly service configuration changes.
  • A comprehensive set of asynchronous and low-level synchronization primitives and OS abstractions.
  • Asynchronous drivers for MongoDB, Postgres, Redis, and other databases. 
  • Asynchronous drivers for data transfer protocols, including HTTP, GRPC, and TCP, and for tasks including construction and cancellation.

A July 29 bulletin announcing the beta of Userver emphasizes the simplicity of the Userver development process, claiming even interns and students can write and deploy to production a new microservice in just a week. The bulletin notes that issues, including errors with multithreading, are caught at compile time. Documentation for Userver can be found at userver.tech. The framework is published under an Apache 2.0 license.

The beta of Userver follows revelations of a potential successor to C++, a language called Carbon. Carbon is currently in an experimental phase.

admin

This website stores cookies on your computer.