46
Create a 20 Times Faster Database Engine Optimized to MMOGs Shuichi Kurabayashi Technical Advisor/Director of Cygames Research Cygames, Inc. [email protected]

Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Create a 20 Times Faster Database Engine Optimized to MMOGs

Shuichi KurabayashiTechnical Advisor/Director of Cygames ResearchCygames, [email protected]

Page 2: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Summary

A simple in-house database engine tailored to MMOGs is highly effective to provide mobile MMOGs for multi-millions unique users.

Legacy Full-Featured DBMS

Lock-Free I/O Operations

Simplified Relational Access

Minimal & Tailored DBMS

Authentication Security

Encryption Transaction

Data Mining Full SQL

Many Business Functions

Page 3: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Legacy Full-Featured DBMS

Lock-Free I/O Operations

Simplified Relational Access

Minimal & Tailored DBMS

Authentication Security

Encryption Transaction

Data Mining Full SQL

Many Business Functions

Game developers do not use almost of those business-oriented functions

It is easy to implement the minimal database management system.

Page 4: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

My message is:

Page 5: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Quick Introduction

Who are you?

What is Cygames?

What is problem?

Page 6: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Introduction: Who I am

• Technical advisor of Cygames, Inc. Also Director of Cygames Research.

• Project Associate Professor at the Graduate School of Keio University

Shuichi Kurabayashi, Ph.D.

Page 7: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Introduction: Cygames is one of the largest mobile game developers in Japan

Known as the developer of the wildly popular card battle game “Rage of Bahamut”.

Recently released “Shadowverse”.

Page 8: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Background: We have been providing mobile MMOGs for 10 millions users.

0

1,000,000

2,000,000

3,000,000

4,000,000

5,000,000

6,000,000

7,000,000

8,000,000

9,000,000

10,000,000

0 5 10 15 20 25

The

nu

mb

er o

f re

gist

ered

use

rs

0

1,000,000

2,000,000

3,000,000

4,000,000

5,000,000

6,000,000

7,000,000

8,000,000

9,000,000

10,000,000

0 5 10 15 20 25

The

nu

mb

er o

f re

gist

ered

use

rs

months after release

Page 9: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Background: Mobile gaming is an important subject of DB Research

Tokyo Stock Exchange

6,700/sec(400,000/min) transactions

Twitter

40,000/sec messages at peak.

Mobile game (Japan)

100,000/sec transactions in average.

Page 10: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Problem Definition

● Modern MMOGs require databases to support large-scale availability, strong consistency, and real-timeresponse.

● It is difficult to support such capabilities efficiently by using conventional systems.

MMOG

consistency

availability

real-time

Page 11: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Consistency

AvailabilityPartition-tolerance

http://berb.github.io/diploma-thesis/original/061_challenge.html

CAP Theorem● C: Consistency of data

● After data has been updated, if something else references that data, it will always be guaranteed that the updated data can be referenced.

● A: Availability of the system

● No matter what the current situation, the system will continue to operate.

● P: Tolerance to network partitions

● Data can be distributed.

Page 12: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Consistency

AvailabilityPartition-tolerance

http://berb.github.io/diploma-thesis/original/061_challenge.html

CAP Theorem● C: Consistency of data

● After data has been updated, if something else references that data, it will always be guaranteed that the updated data can be referenced.

● A: Availability of the system

● No matter what the current situation, the system will continue to operate.

● P: Tolerance to network partitions

● Data can be distributed.

Out of these three guarantees, only two can be fulfilled at a time.

Page 13: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Consistency

AvailabilityPartition-tolerance

http://berb.github.io/diploma-thesis/original/061_challenge.html

Choosing Appropriate System

CA: conventional relational database systems, such as MySQL, Oracle, and SQL server,strong consistency

AP: SNS,NoSQL, eventual consistency

CP: Apache Hbase, Hadoop, BigTable,Good for analytics

Page 14: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Consistency

AvailabilityPartition-tolerance

http://berb.github.io/diploma-thesis/original/061_challenge.html

CAP Theorem

CA is the most important for games, because games require strong consistency and fast response

AP: SNS,NoSQL, eventually consistency

CP: Apache Hbase, Hadoop, BigTable,Good for analytics

Page 15: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Part

itio

nin

g …LiveStorage Layer

MySQL(master)

MySQL(slave)

MySQL(log)

replication

Cluster Set 1

Sharding

Cluster Set 2

MySQL(master)

MySQL(slave)

MySQL(log)

Cluster Set 3

MySQL(master)

MySQL(slave)

MySQL(log)

Cluster Set 32

MySQL(master)

MySQL(slave)

MySQL(log)

Fusion-ioFusion-io Fusion-io Fusion-io

Data Mining Environment

Customer Support DB

Analytics Layer

Data Warehouse Systems and Statistical Analysis Systems

Typical Backend ArchitectureWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

ServerWeb

Server…

Page 16: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Primitive Unit

Part

itio

nin

g

MySQL(master)

MySQL(slave)

MySQL(log)

replication

Cluster Set 1

Fusion-io

Web Server

memcached

PHP

MySQL stores status data, which are updated in a real-time manner.

Main memory, memcachedstores static data shared among all the PHP processes.

This bandwidth is the most precious resources.

Page 17: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Part

itio

nin

g …LiveStorage Layer

MySQL(master)

MySQL(slave)

MySQL(log)

replication

Cluster Set 1

Sharding

Cluster Set 2

MySQL(master)

MySQL(slave)

MySQL(log)

Cluster Set 3

MySQL(master)

MySQL(slave)

MySQL(log)

Cluster Set 32

MySQL(master)

MySQL(slave)

MySQL(log)

Fusion-ioFusion-io Fusion-io Fusion-io

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server

Web Server…

Combination of sharding (horizontal decomposition) and partitioning (vertical decomposition) brings high-level parallelism

Page 18: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Part

itio

nin

g …LiveStorage Layer

MySQL(master)

MySQL(slave)

MySQL(log)

replication

Cluster Set 1

Sharding

Cluster Set 2

MySQL(master)

MySQL(slave)

MySQL(log)

Cluster Set 3

MySQL(master)

MySQL(slave)

MySQL(log)

Cluster Set 32

MySQL(master)

MySQL(slave)

MySQL(log)

Fusion-ioFusion-io Fusion-io Fusion-io

Data Mining Environment

Customer Support DB

Analytics Layer

Data Warehouse Systems and Statistical Analysis Systems

Data mining process including JOIN operations is carried out by replica DBs that are replicated from the master database asynchronously.

Page 19: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

MySQL is working now. But…

Operation can be highly inefficient and unprofitable

Not so scalable

Large maintenance cost

Capacity per machine is not so high

Page 20: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

RDB functionalities are appropriate for C-A requirements, but it is too fat.

Overhead-1: Too Generic Structure

Overhead-3: Not utilizing modern hardware

Overhead-2: Not utilizing data access pattern in games

3 Overheads that decrease RDB’s performance

Page 21: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Overhead-1:Too Generic Structure!

Internal Schema

Conceptual Schema

ExternalSchema-2

ExternalSchema-1

ExternalSchema-n

Data Model supported by Apps

Data Model supported by DBMS

Data Modelsupported by storage

CREATE TABLE(…);

TupleTableSlot *rec;

Page 22: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Overhead-1:Too Generic Structure!

● Planner (logical optimization)● Rewrites queries for better

performance, by analyzing queries as relational calculus.

● Executor (physical optimization)● Executes query primitives such

as relational algebras.

● Storage Subsystem● Reads and writes disk storages.

Storage

Executer

Planner

I/O operations

Internal declarative expression

Procedural expression of relational algebra

SQL

Page 23: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Insert Update Select Real-time Consistency Query Type

Legacy Web(e-commerce)

Small Small Large No StrongConsistency

Dynamic(mutable)

SNS(Large Scale Web Apps)

Large Small Massively Large

No EventualConsistency

Dynamic(mutable)

IoT (Stream DB) Massively Large

no Small Yes Application-Dependent

Static (immutable)

Mobile Game Small Massively Large

Massively Large

Yes Strong Consistency

Static (immutable)

Let’s resolve Overhead-2:Not utilizing data access pattern in games

We faces technical requirements that are essentially different from a conventional DBs

Page 24: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Let’s resolve Overhead-3:Not utilizing modern hardware

The throughput performance becomes from 10 to 20 times faster, due to the multi-core CPU with the high parallelism and a SSD with the highly parallel access.

Page 25: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Solution

Query Pre-Compilation (Immutable Query)

Lower Footprint query processing

Lock-Free Thread Scheduling

Page 26: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Static Query Analysis is effectiveIf we can know all the query to be processed,

we can apply holistic optimization by

analyzing their data access pattern and

implicit race condition among them.

CySQLImmutable Queries (Staticallyanalyzed and compiled queries)

QueryParams

query

query

query

query

query

query

App Server

QueryParams

QueryParams

QueryParams

QueryParams

QueryParams

Page 27: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Legacy Query Model

● Legacy query model cannot optimize holistic query, because queries are submitted dynamically.

Legacy DB

App Server

SQLSQL

SQL

Page 28: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Immutable Query

CySQLImmutable Queries (Staticallyanalyzed and compiled queries)

QueryParams

query

query

query

query

query

query

App Server

QueryParams

QueryParams

QueryParams

QueryParams

QueryParams

Deploy-Time Runtime

Immutable query model requires the all queries to be defined at deploy time

Page 29: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Imm

uta

ble

Q

uery

SQL parsing and optimizing takes large cost

Storage

Executer

Planner

Apps

We can bypass the planner and the executor, by compiling SQL into executable machine code.

Controlling transaction manager directly from the application, we can achieve nearly 10 times faster performance than SQL

Page 30: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Query Processor Bypassing

SQL executableSELECT * FROM table;

01001001001010011101010010011101100011

Introducing query pre-compilation and bypassing planner and executor

SQL pre-compilation Bypassing SQL modules

executor

storage

plannerstorage

Page 31: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Lock-Free Transaction Processing

Legacy RDB embraces a lot of overhead of sync inside the DB engine for lock mechanism. Each of those overheads is small, but small overhead will be accumulated, so each overhead is the cost which can't be ignored.

Row-level lock

Snapshot creation for MVCC Buffer lock

Page 32: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Can we realize Lock-Free?

By using the thread scheduling specialized in the data access pattern specific to the game, multiple threads read/writes databases without locks.

Database

query

query

I know everything

about queries

• race condition,• dependency,• prioritybetween queries

Page 33: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Basic Concept of Lock-Free Thread SchedulingQuery-1

Job Queue

Job

Job

Job

Job

Job

Job

Job

Job

Job

JobJob

Depends on

Depends onJob

The scheduler recognizes dependencybetween jobs. It re-orders jobs according tothe those race conditions and atomicity.

ExecutionPhase

QueueingPhase Job

Worker Thread Pool

One query constructs one queue.

Gate Keeper

Query-2Job Queue

Query-3Job Queue

Query-nJob Queue

Page 34: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

In the immutable query model, DB engine can schedule threads perfectly without synchronization lock.

● Because the DB engine can analyze race condition between queries statically.

● The thread scheduling strategy is easy: “Do not schedule the queries that cannot be executed simultaneously.”

Page 35: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

The number of CPU cores are increasing for both energy and performance efficiency.

2 2

4

8

10

2010 2011 2012 2014 2015

Th

e N

um

ber o

f C

ores

image source: https://www.qualcomm.com/sites/ember/files/styles/optimize/public/components/one-column-hdi/bottom/chip-tiny-625_1.png?itok=RfSGmx-s

image source: http://mediatek-helio.com/x20/img/X20.png

Page 36: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Parallelism in I/O Devices

Not so parallel Highly Parallel

NAND

NAND

NAND

Contro

ller

HDD SSD

Page 37: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Parallelism in I/O Devices

Not so parallel Highly Parallel

NAND

NAND

NAND

Contro

ller

HDD SSD

Only this parts (head) can read/writedata

Every chip can read/write data in parallel

Page 38: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Comparison of the prototype and MySQL: UPDATE command

3 6.3 10.474

144

291

0

50

100

150

200

250

300

350

500000 1000000 2000000

Th

ro

ug

hp

ut(

sec)

Update Count

Prototype MySQL

Executing UPDATE operations by using a randomly generated value.

Page 39: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Theoretical Conclusion

Increase the number of threads as manyas you can

Page 40: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Implementation!

● Here I introduce a quick implementation method of read-only database engine.

Page 41: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Use Case: Fast Search Engine lo

gic

al c

onju

nctio

n

logical disjunction

https://shadowverse-portal.com/

Page 42: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Query type detection

Those are sub-queries corresponds to the immutable queries

Page 43: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Query type detection

When the target data is fixed, we can execute those sub queries before the runtime.

Page 44: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Data Structure

Attributes

Queries

Query Results

Each block represents anarray that stores resultsof the specific queriesapplied to the specificattributes.

Page 45: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Conclusion

• You can implement tiny RDB within a hour.

• Increase the number of threads as many as you can

Page 46: Create a 20 Times Faster Database Engine Optimized to MMOGs · Job Job Job Job Job Job Job Job Job Job Job Depends on Job Depends on The scheduler recognizes dependency between jobs

Recommended Books

● Database Systems: The Complete Book (2nd Edition) 2nd Edition by Hector Garcia-Molina, Jeffrey D. Ullman, Jennifer Widom

● Introduction to Algorithms, 3rd Edition (MIT Press) 3rd Edition by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein