Company
Date Published
Author
Trond Norbye, Senior Developer, Couchbase
Word count
751
Language
English
Hacker News points
None

Summary

The tutorial explains how to implement asynchronous operations in an engine that initially runs synchronous filesystem I/O, which limits the speed of serving client requests. By using the server API available in the `create_instance` function, it introduces asynchronous methods to prevent blocking the engine API during `get` and `store` operations. The tutorial emphasizes that the design is focused on explaining the engine API rather than optimizing efficiency, suggesting potential improvements like using a thread pool instead of creating new threads for each task due to the overhead involved. It details the process of dispatching requests to new threads, using `notify_io_complete` to inform the memcached core when operations are complete, and handling errors if they occur. The code snippets provided illustrate how to update the `fs_get` method to run asynchronously and store results, with a structure for tasks that includes engine pointers, cookies, and operation-specific data.