TL;DR
This paper explores using JavaScript as a way to extend the functionality of low-latency, in-memory key-value stores like RAMCloud. The authors found that JavaScript, particularly with the V8 engine and asm.js, offers a compelling balance of performance and low overhead for executing custom logic directly on the data, making it a promising approach for building more flexible and powerful data services.
What Problem Does This Paper Address?
High-performance, in-memory key-value stores like RAMCloud can achieve extremely low access latencies (microseconds) and high throughput (millions of operations per second). However, these systems often have limited feature sets, forcing developers to build custom stores or add complex logic on the client side. This lack of extensibility creates a bottleneck for applications requiring inter-record dependencies or custom data processing, as even the fastest client-server round trips can be too slow. The paper investigates how to push computation closer to the data within these stores to overcome this limitation.
Methods
The authors evaluate JavaScript as a candidate for running user-supplied logic (stored procedures) within an in-memory key-value store. They consider several criteria for evaluating potential approaches:
- Native Performance: The ability to achieve performance close to native code.
- Low Invocation Overhead: The cost of calling a stored procedure should be minimal to avoid impacting overall throughput.
- Runtime Reconfigurable: Procedures should be installable and removable without taking the system offline, crucial for multi-tenant environments.
- Inexpensive Isolation: Efficiently isolating different tenants' code is essential.
They compare JavaScript against native C++ code and other isolation techniques. The core of their evaluation involves microbenchmarks to measure:
- Installation Costs: Time to compile and install procedures.
- Invocation and Entry/Exit Costs: The overhead of calling a procedure and interacting with the database.
- Isolation Costs: The overhead of switching between protection domains.
- Performance on Compute and Memory-bound Tasks: How JavaScript performs on different types of workloads.
They also explore the use of asm.js, a subset of JavaScript that can be highly optimized by JavaScript engines, as a way to achieve near-native performance for compute-bound tasks.
Datasets
Not discussed in the paper. The evaluation uses microbenchmarks with synthetic data (1 GB of 64 B records) to simulate queries over a relation.
Key Insights and Ideas
- JavaScript as a Sweet Spot: JavaScript, with its Just-In-Time (JIT) compilation and built-in sandboxing, offers a surprisingly good trade-off between performance and the overhead of isolation, especially compared to traditional OS-level process isolation.
- Low Context Switch Costs: V8's context switching mechanism is significantly faster (8.7% of conventional process context switch) than traditional OS methods, making it feasible to run many tenant procedures efficiently.
- Minimizing Data Movement is Key: The ability to pass data structures (like scatter-gather lists) directly to the network card for zero-copy DMA, without the CPU touching the data, is a critical optimization for low-latency stores. JavaScript can facilitate this by operating on these structures.
- asm.js for Performance-Critical Tasks: For compute-bound operations,
asm.jscan provide performance very close to native C++ code, making JavaScript a viable option even for demanding tasks. - The "Chase" Procedure Bottleneck: Procedures that involve multiple sequential lookups (like fetching a record and then using its value to fetch another) are significantly accelerated by pushing computation into the store, as it avoids multiple network round trips.
Key Results
- Invocation Overhead: JavaScript procedure invocation from C++ is 11.4x faster than using hardware-protected processes.
- Isolation Overhead: JavaScript context switches are 72x faster than hardware-based isolation for accessing data.
- Performance on Simple Queries: For memory-bound queries (Q1, Q2, Q3), JavaScript was 18-39% slower than native C++.
- Performance on Compute-bound Queries: For a compute-bound query (Q4), JavaScript was 2.2x faster than the native version relying on
glibc'spowimplementation. - asm.js Performance:
asm.jscode was only 2-10% slower than native C++ code on average across the tested queries. - V8 Context Switch Cost: A V8 context switch is 8.7% of a conventional process context switch.
Limitations and Future Work
- JavaScript Performance Fragility: The authors acknowledge that JavaScript performance might be more fragile than native code, especially for certain types of procedures. They raise the question of which procedures might perform poorly and if those cases are prohibitive.
- CPU Branch Prediction: V8 is harder on CPU branch prediction than native code, which can impact performance on certain workloads (e.g., selectivity around 50%).
- Future Work: The authors plan to embed V8 into the RAMCloud server, develop a richer API for JavaScript procedures that exposes low-level database functionality, and experiment with realistic, large-scale applications. They also want to explore other isolation approaches for latency-sensitive operations.
Summary updated