Could Go Defeat Java in the Cloud Computing Era?

With the emergence of new asynchronous frameworks and languages such as Go, the Alibaba tech team now wonder whether Java is still applicable to the latest cloud scenarios

Introduction

Quick Start

curl https://gosling.alibaba-inc.com/sh/enable-wisp2.sh | sh
ajdk 8.7.12_fp2 rpm
sudo yum install ajdk -b current #
java -XX:+UseWisp2 .... #
  • Coroutine […] indicates a coroutine.
  • Active indicates the number of times a coroutine is scheduled
  • Steal indicates the number of times a coroutine is stolen
  • Preempt indicates the number of times a time slice is preemptible

Overhead of Multithreading

Misunderstanding 1: Context Switching is Caused by Accessing the Kernel

pipe(a);
while (1) {
write(a[1], a, 1);
read(a[0], a, 1);
n += 2;
}

Misunderstanding 2: The Overhead of Context Switching is High

Overhead

Relationship Between Asynchronization and Coroutine

private void writeQuery(Channel ch) {
ch.write(Unpooled.wrappedBuffer("query".getBytes())).sync();
logger.info("write finish");
}
private void writeQuery(Channel ch) {
ch.write(Unpooled.wrappedBuffer("query".getBytes()))
.addListener(f -> {
logger.info("write finish");
});
}
suspend fun Channel.aWrite(msg: Any): Int =
suspendCoroutine { cont ->
write(msg).addListener { cont.resume(0) }
}
suspend fun writeQuery(ch: Channel) {
ch.aWrite(Unpooled.wrappedBuffer("query".toByteArray()))
logger.info("write finish")
}

Performance Comparison: Manual Asynchronous Programming vs WISP Programming

Write a New Application Based on Existing Components

Develop a New Application from Scratch

  • Thread control is more precise. For example, binding the connections of the proxy client and backend connections to the same Netty thread and localizing all thread operations.
  • Almost no coroutine runtime and scheduling overhead (about 1%) is generated.

Adapted Workload

  • In WISP 1, the parameters of connected applications and the implementation of WISP are deeply adapted.
  • In WISP 2, all threads are converted into coroutines, and no adaption is needed.

Project Loom

  • synchronized/Object.wait() occupies threads, so the CPU cannot be fully utilized.
  • Deadlocks may also be generated, which is inevitable in WISP. WISP only subsequently added support for ObectMonitor.
  • Loom is unfriendly to frameworks like Dubbo, and almost all frameworks in the stack contain reflection.

FAQs

Why is the Overhead Small in Case of Scheduled Coroutines?

Why Doesn’t WISP 2 Use ForkJoinPool to Schedule Coroutines?

What Do You Think of Reactive Programming?

What are the Main Constraints at the Moment?

Alibaba Tech

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Tech

First-hand & in-depth information about Alibaba's tech innovation in Artificial Intelligence, Big Data & Computer Engineering. Follow us on Facebook!