27
Super Server Super Server in Firebird 3 in Firebird 3

Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Embed Size (px)

Citation preview

Page 1: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Super Server Super Server in Firebird 3in Firebird 3

Page 2: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Sponsors !

Page 3: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 33

Introduction into Firebird3● Firebird3 files

● Root directory– network server (firebird.exe)– client library (fbclient.dll)– utilities (gbak, gfix, isql, etc)– configuration files (*.conf)– security database (security3.fdb)– support libraries (icu*.dll, ib_util.dll, MSVC CRT dll's)– support files (firebird.msg, icu*.ddat, license.txt)

Page 4: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 34

Introduction into Firebird3● Firebird3 files

● bin sub-directory– yes, no more bin sub-directory on Windows

● intl sub-directory– internalization support library (fbintl.dll, fbintl.conf)

● plugins sub-directory– engine itself (engine12.dll)– trace plugin (fbtrace.dll)– auth plugins (srp.dll, legacy_auth.dll, legacy_usermanager.dll)– UDR engine plugin

● udf sub-directory– standard UDF libraries

Page 5: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 35

Introduction into Firebird3● Unified network listener

● single network listener firebird.exe– no more fbserver.exe\fb_inet_server.exe

● launch new process for incoming connection– process mode: by default

● launch new thread for incoming connection– threading mode: add switch -m

Page 6: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 36

Introduction into Firebird3● Unified client library and unified engine library

● No more fbclient.dll\fbembed.dll– single client: fbclient.dll

● used for remote and embedded access – single engine: engine12.dll

● used as Super Server and Classic Server● Super\Classic mode of engine defined by two new

firebird.conf settings:– SharedDatabase– SharedCache

Page 7: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 37

Introduction into Firebird3● Classic Server

– network server in process mode (firebird -a)– SharedDatabase = true– SharedCache = false

● Super Server– network server in threading mode (firebird -a -m)– SharedDatabase = false– SharedCache = true

● Super Classic (obsolete?)– network server in threading mode (firebird -a -m)– SharedDatabase = true– SharedCache = false

Page 8: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 38

Introduction into Firebird3● Embedded

– need both fbclient.dll and plugins\engine12.dll● Embedded in Classic mode

– SharedDatabase = true– SharedCache = false

● Embedded in Super mode– SharedDatabase = false– SharedCache = true

Page 9: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 39

Super Server● Main difference from Classic

● All attachments are handled by the single process● Shared common data

– metadata cache– page cache– transaction inventory cache

● Hand-made scheduler: cooperative multitasking– single scheduler, single active thread in process– threads voluntary switched control to each other

● Metadata still synchronized by LM● Page cache not used LM

– individual “latches” for page buffers

Page 10: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 310

Super Server before Firebird3● Pluses

● shared caches - used much less memory than lot of Classic processes

● single active thread - almost no need to synchronize concurrent access to in-memory structures

● Minuses● single active thread - no way to use more than one CPU\core

– SMP is not possible● cooperative multitasking is very far from fair scheduling

– “heavy” query in one attachment could get more CPU and slowdown queries in another attachments

Page 11: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 311

Super Server in Firebird3● On the way to the true Super Server

● shared page cache● shared TIP cache● metadata cache is not shared (private per attachment)● no more custom scheduler, all threads works in parallel

– SMP is supported now● new synchronization schema

Page 12: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 312

Page Cache● Page buffers

● used to cache contents of database file pages– descriptor of page buffer, data buffer itself

● Control structures● Hash table

– used to fast search for page buffer by given page number● LRU queue

– defines page buffer eviction policy● Precedence graph

– used to implement “careful write” policy● Dirty pages queue

– what to write on commit

Page 13: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 313

Page Cache● Synchronization

● individual latch for every page buffer– latch is a lightweight RW-lock– used always (despite of SharedCache setting)

● individual Lock Manager's lock for every page buffer– used in SharedCache = false (Classic) mode only

● separate RW-lock for every control structure– hash table– LRU queue– precedence graph– dirty queue

Page 14: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 314

Page Cache● Fine-grained synchronization is not free !● Every page access consists of following steps

● fetch page buffer– read contents from disk, if necessary

● access (use) page buffer – read record data, for example

● release page buffer

Page 15: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 315

Page Cache● Cost of page access in Super Server, before v3

● fetch page– find buffer in hash table– if buffer is not used - increment use_count– else - voluntary switch to another thread and wait while current

buffer owner granted us access● release page

– decrement use_count– grant access to waiting tread(s)

● Minimal cost is two changes of use_count– very, very cheap

Page 16: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 316

Page Cache● Cost of page access in Super Server, in v3

● fetch page– acquire lock for hash table– find buffer in hash table– release lock for hash table– acquire latch for page buffer

● interlocked increment of latch state,● or wait while current latch owner granted us access

● release page– release latch for page buffer

● interlocked decrement of latch state– grant access to waiting tread(s)

● Minimal cost is four interlocked operations

Page 17: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 317

Benchmark, single thread read

Not cached Firebird File System0102030405060708090100

83

7 10

92

10 13

Firebird 2.5Firebird 3.0

Tim

e, s

ec

SELECT COUNT(*) FROM STOCK10'000'000 rowsMemory buffers = 500'000Reads from disk to cache = 418'604 ' not cachedReads from disk to cache = 0 ' cached by FirebirdReads from disk to cache = 418'822 ' cached by File SystemFetches from cache = 20'837'432

Page 18: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 318

Benchmark, single thread read

Not cached Firebird File System0

20

40

60

80

100

120104

15 17

101

18 20

Firebird 2.5Firebird 3.0

Tim

e, s

ec

SELECT COUNT(DISTINCT S_W_ID), COUNT(DISTINCT S_I_ID) FROM STOCK10'000'000 rowsMemory buffers = 500'000Reads from disk to cache = 418'604 ' not cachedReads from disk to cache = 0 ' cached by FirebirdReads from disk to cache = 418'822 ' cached by File SystemFetches from cache = 20'837'432

Page 19: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 319

Benchmark, multithreaded read● Multithreaded read only benchmark

● Table STOCK have 10'000'000 records – 100 warehouses, 100'000 items in each

● Each reader reads random items in own warehouse● We don't test network subsystem

– client application executes procedure, which selects a number of random items (100 by default)

● We don't test IO subsystem– before each test series we ensure whole table STOCK is fully

cached by filesysem

Page 20: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 320

1 2 4 8 16 32 640

50100150200250300350400450 414 416 411 408 403 384 365377 382

359

217

168 154 142

Super Server, page cache 2048 Firebird 2.5Firebird 3.0

Threads

Cou

ntBenchmark, multithreaded read

1 2 4 8 16 32 640

50100150200250300350400450

Threads

Cou

nt

Page 21: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 321

Benchmark, multithreaded read

1 2 4 8 16 32 640

100200300400500600700

Threads

Cou

nt

1 2 4 8 16 32 640

100200300400500600700

414 416 411 408 403 384 365377 382 359

217168 154 142

390

616

491

324

219 190 176

Super Server, page cache 2048 Firebird 2.5FB 3.0.0.31369FB 3.0.0.31385

Threads

Cou

nt

Page 22: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 322

Benchmark, multithreaded read

1 2 4 8 16 32 640

100200300400500600700

Threads

Cou

nt

1 2 4 8 16 32 640

100200300400500600700

414 416 411 408 403 384 365377 382 359

217168 154 142

371

612538

466

383323

291

Super Server, page cache 2048 Firebird 2.5FB 3.0.0.31369FB3 hash table patch

Threads

Cou

nt

Page 23: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 323

1 2 4 8 16 32 640

100200300400500600700

350

527

620569 561 535 513

330

476

572 550 533498

451

Super Classic, page cache 256 Firebird 2.5Firebird 3.0

Threads

Cou

ntBenchmark, multithreaded read

1 2 4 8 16 32 640

100200300400500600700

Threads

Cou

nt

Page 24: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 324

Benchmark, multithreaded read

1 2 4 8 16 32 640

500

1000

1500

2000

873 867 833 811 803 799 787766

1208

1794 1735 1714 16411541

Super Server, page cache 500'000 Firebird 2.5Firebird 3.0

Threads

Cou

nt

1 2 4 8 16 32 640

500

1000

1500

2000

Threads

Cou

nt

Page 25: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 325

1 2 4 8 16 32 640

5000

10000

15000

20000

25000

30000

5271

6745

10660 1109110452 10429 9946

8081

12732

15519 15786

12465

90137947

11437

18390

25631

23647

19203

15275

10469

2.5 Super Server2.5 Super Classic3.0 Super Server

Terminals

tpm

CBenchmark, TPCC

Page 26: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 326

Benchmark, TPCC

1 2 4 8 16 32 640

5000

10000

15000

20000

25000

30000 2.5 Super Server2.5 Super Classic3.0 Super Server

Terminals

tpm

C

Page 27: Super Server in Firebird 3 - Firebird: The true open ... · 10 Prague 2014 Firebird 3 Super Server before Firebird3 Pluses shared caches - used much less memory than lot of Classic

Prague 2014 Prague 2014 Firebird 3 Firebird 327

Questions ?Questions ?

Firebird official web site

Firebird tracker

THANK YOU FOR ATTENTIONTHANK YOU FOR ATTENTION

[email protected]