Understanding the lock manager internals with the fb lock print utility

Embed Size (px)

DESCRIPTION

This session will provide a short introduction to the Firebird lock manager and its usage patterns. It will describe how the lock manager can affect the performance of highly loaded systems and outlines the possible bottlenecks and other problems like unexpected lock-ups/freezes that may require special analysis. The structure of the lock table will also be explained. It will also include a detailed description of the fb_lock_print utility and its usage that will enable the research of issues that are related to the lock manager. A few practical examples illustrating how to analyze the utility output will be provided. This session is mainly of interest to Classic Server users and DBAs.

Citation preview

  • 1. Understanding the lock manager with the fb_lock_print utility Dmitry Yemanov mailto:[email protected] Firebird Project http://www.firebirdsql.org/

2. Synchronization in Firebird

  • Internal vs external locks
    • Mutexes, spinlocks, RW locks, latches
  • 3. Lock manager
  • Features of the global locks
    • Multiple states (SR, PR, SW, PW, EX)
  • 4. Blocking notifications

5. Deadlock detection 6. Monitoring abilities 7. Lock Types and their Usage

  • Lock types
    • Database lock
  • 8. Existence locks (table, procedure, index, collation)

9. Table access locks 10. Transaction locks 11. Sweep, shadow, monitoring, etc locks

    • Page locks (!)

12. Lock Types and their Usage

  • Lock types

LCK_database = 1 // Root of lock tree LCK_relation = 2 // Individual relation lock LCK_bdb = 3 // Individual buffer block LCK_tra = 4 // Individual transactionlock LCK_rel_exist = 5 // Relation existence lock LCK_idx_exist = 6 // Index existence lock LCK_attachment = 7 // Attachment lock ... 13. Locks and Firebird Architectures

  • SuperServer
    • No page locks
  • 14. Small lock table

15. Fast LM operations

  • Classic and SuperClassic
    • Page locks are widely used
  • 16. Large lock table

17. LM operations may require IPC 18. Lock Manager in Classic IPC IPC IPC Connection 1 Connection 2 fb_inet_server fb_inet_server fb_lock_mgr Lock table (shmem) 19. Inside the Lock Table

  • Block types
    • Header section
  • 20. Lock owners

21. Lock resources 22. Lock requests

  • Internals
    • Single mutex around the shmem region
  • 23. Remappings

24. Hash table of lock keys 25. Inside the Lock Table Lock resource Series: page lock Key: 01:75 State: PR Lock request 1 PR (granted) Lock request 3 EX (pending) Lock request 4 EX (pending) Owner 1 PID = 1008 Owner 3 PID = 870 Owner 4 PID = 114 Lock request 2 PR (granted) Owner 2 PID = 788 26. Inside the Lock Table

  • Owner states
    • Waiting = 0x4
  • 27. Signaled = 0x10
  • Request states
    • Pending = 0x2
  • 28. Blocking = 0x1

29. Blocking seen = 0x100 30. Tuning the Lock Manager

  • Configuration options
    • LockMemSize (1MB) ~= * * 100
  • 31. LockSemCount (32) deprecated in v2.5

32. LockHashSlots (1009)

  • Other considerations
    • FIREBIRD_LOCK envvar

33. Using the Lock Print Utility

  • Output control switches
    • -o [wners]
  • 34. -l [ocks]

35. -r [equests] 36. -s [eries] 37. -a [ll] 38. -w [ait list]

  • Default output
    • Header and owners only

39. Using the Lock Print Utility

  • Interactive mode
    • -i [aotw]
  • 40. Acquires, operations, types, waits

41. Seconds and intervals

  • Other options
    • -c
  • 42. -d or -f

43. -m 44. Questions?