auth_rx_wiki/Auth-Redux-vs-SQLite3.md

17 KiB

Recently, I decided to benchmark the performance of Auth Redux in order to weed out any potential bottlenecks. So I put it to the test against two different SQLite3 implementations using a database of over 522,000 records from the JT2 server

Much to my surprise, Auth Redux doesn't suffer at all when it comes to raw speed. It's insanely fast compared to both sauth and the new Minetest 5.0 builtin. For every test, it vastly out-performed these other authentication handlers. I'm talking orders of magnitude amounting to hundreds and even thousands of milliseconds, as shown by these baseline measurements:

Even the database file size of Auth Redux is just 2/3rds that of auth.sqlite used by Minetest 5.0. And yet the schema is far more extensive (including total time spent playing, initial login timestamp, total player sessions, etc.) When it comes to rsyncing files in the hundreds of megabytes over SSH, this can make a huge difference.

Perhaps, the biggest area of concern for most admins is the execution time during player joins. If a high-traffic server averages around 30 players joining every minute at peak hour, sauth would consume over 20 seconds of CPU cycles (that is 1/3 of server time spent processing authorization). Meanwhile, auth_rx clocks in at just 3.8 milliseconds after 30 player joins.

For each test below, I performed five independent trials and averaged the results to get the most accurate figure possible.

As the benchmarks below reveal, there is no discernible benefit to using an SQLite3 backend for authentication, whether in terms of reliability or performance. If anything, SQLite3 databases are a hindrance when it comes to random access of large volumes of data, and more than likely the culprit for why some high-traffic servers lately are experiencing notable lag spikes.

***************************************************
*                                                 *
*  BENCHMARK RESULTS :: sauth Mod                 *
*                                                 *
***************************************************

-----------------
-- Player Join --
-----------------

Trial #1				
on_prejoinplayer:   191.557 ms
get_auth:           182.467 ms
get_auth:             0.006 ms
get_auth:             0.002 ms
on_joinplayer:       282.47 ms

Trial #2				
on_prejoinplayer:    46.517 ms
get_auth:            45.812 ms
get_auth:             0.006 ms
get_auth:             0.001 ms
on_joinplayer:      283.108 ms

Trial #3				
on_prejoinplayer:   222.382 ms
get_auth:           223.67 ms
get_auth:             0.005 ms
get_auth:             0.001 ms
on_joinplayer:      286.856 ms

Trial #4				
on_prejoinplayer:    40.254 ms
get_auth:            40.191 ms
get_auth:             0.005 ms
get_auth:             0.001 ms
on_joinplayer:      277.572 ms

Trial #5				
on_prejoinplayer:   113.755 ms
get_auth:           113.559 ms
get_auth:             0.005 ms
get_auth:             0.002 ms
on_joinplayer:      302.207 ms

grand total:       2652.377 ms (530.475 ms per trial)

---------------------
-- New Player Join --
---------------------

Trial #1					
on_prejoinplayer:   667.582 ms
create_auth:         55.143 ms
get_auth:           239.711 ms
get_auth:             0.003 ms
on_joinplayer:      284.481 ms

Trial #2					
on_prejoinplayer:   651.416 ms
create_auth:         70.514 ms
get_auth:           241.781 ms
get_auth:             0.002 ms
on_joinplayer:      291.393 ms

Trial #3					
on_prejoinplayer:   653.206 ms
create_auth:         81.624 ms
get_auth:           241.273 ms
get_auth:             0.003 ms
on_joinplayer:      286.546 ms

Trial #4					
on_prejoinplayer:    52.127 ms
create_auth:         47.274 ms
get_auth:           242.559 ms
get_auth:             0.003 ms
on_joinplayer:      289.712 ms

Trial #5					
on_prejoinplayer:   652.577 ms
create_auth:         50.841 ms
get_auth:           241.937 ms
get_auth:             0.003 ms
on_joinplayer:      287.050 ms

grand total:       6228.747 ms (1245.749 ms per trial)

--------------------
-- Set Privileges --
--------------------

Trial #1
get_auth:             0.003 ms
get_auth:             0.001 ms
get_auth:            46.787 ms
get_auth:             0.002 ms
get_auth:             0.002 ms
get_auth:             0.000 ms
set_privileges:     332.599 ms
get_auth:             0.003

Trial #2
get_auth:             0.004 ms
get_auth:             0.001 ms
get_auth:           222.644 ms
get_auth:             0.002 ms
get_auth:             0.001 ms
get_auth:             0.001 ms
set_privileges:     296.785 ms
get_auth:             0.004 ms

Trial #3
get_auth:             0.003 ms
get_auth:             0.000 ms
get_auth:            40.614 ms
get_auth:             0.002 ms
get_auth:             0.001 ms
get_auth:             0.001 ms
set_privileges:     298.970 ms
get_auth:             0.004 ms

Trial #4
get_auth:             0.003 ms
get_auth:             0.001 ms
get_auth:           113.697 ms
get_auth:             0.002 ms
get_auth:             0.001 ms
get_auth:             0.000 ms
set_privileges:     296.746 ms
get_auth:             0.004 ms

Trial #5
get_auth:             0.003 ms
get_auth:             0.001 ms
get_auth:           182.452 ms
get_auth:             0.002 ms
get_auth:             0.002 ms
get_auth:             0.001 ms
set_privileges:     287.106 ms
get_auth:             0.003 ms

grant total:       2118.460 ms (423.692 ms per trial)


***************************************************
*                                                 *
*  BENCHMARK RESULTS :: Auth Redux Mod            *
*                                                 *
***************************************************

-----------------
-- Player Join --
-----------------

Trial #1
on_prejoinplayer:     0.059 ms
get_auth:             0.009 ms
get_auth:             0.016 ms
get_auth:             0.006 ms
on_joinplayer:        0.038 ms

Trial #2
on_prejoinplayer:     0.063 ms
get_auth:             0.002 ms
get_auth:             0.005 ms
get_auth:             0.002 ms
on_joinplayer:        0.039 ms

Trial #3
on_prejoinplayer:     0.066 ms
get_auth:             0.002 ms
get_auth:             0.003 ms
get_auth:             0.001 ms
on_joinplayer:        0.039 ms

Trial #4
on_prejoinplayer:     0.064 ms
get_auth:             0.002 ms
get_auth:             0.004 ms
get_auth:             0.001 ms
on_joinplayer:        0.056 ms

Trial #5
on_prejoinplayer:     0.062 ms
get_auth:             0.002 ms
get_auth:             0.005 ms
get_auth:             0.001 ms
on_joinplayer:        0.037 ms

grand total:          0.584 ms (0.117 ms per trial)

---------------------
-- New Player Join --
---------------------

Trial #1
on_prejoinplayer:   521.555 ms
create_auth:          0.101 ms
get_auth:             0.003 ms
get_auth:             0.002 ms
on_joinplayer:        0.039 ms

Trial #2
on_prejoinplayer:   231.001 ms
create_auth:          0.080 ms
get_auth:             0.003 ms
get_auth:             0.001 ms
on_joinplayer:        0.038 ms

Trial #3
on_prejoinplayer:   265.901 ms
create_auth:          0.081 ms
get_auth:             0.003 ms
get_auth:             0.001 ms
on_joinplayer:        0.037 ms

Trial #4
on_prejoinplayer:   265.861 ms
create_auth:          0.099 ms
get_auth:             0.004 ms
get_auth:             0.001 ms
on_joinplayer:        0.038 ms

Trial #5
on_prejoinplayer:   243.255 ms
create_auth:          0.082 ms
get_auth:             0.004 ms
get_auth:             0.001 ms
on_joinplayer:        0.039 ms

total:             1528.334 ms (305.667 ms per trial)

--------------------
-- Set Privileges --
--------------------

Trial #1
get_auth:            0.012 ms
get_auth:            0.005 ms
get_auth:            0.001 ms
get_auth:            0.000 ms
get_auth:            0.007 ms
set_privileges:      0.081 ms
get_auth:            0.001 ms

Trial #2
get_auth:            0.014 ms
get_auth:            0.005 ms
get_auth:            0.001 ms
get_auth:            0.000 ms
get_auth:            0.010 ms
set_privileges:      0.056 ms
get_auth:            0.001 ms

Trial #3
get_auth:            0.014 ms
get_auth:            0.005 ms
get_auth:            0.001 ms
get_auth:            0.000 ms
get_auth:            0.010 ms
set_privileges:      0.056 ms
get_auth:            0.001 ms

Trial #4
get_auth:            0.013 ms
get_auth:            0.005 ms
get_auth:            0.002 ms
get_auth:            0.000 ms
get_auth:            0.005 ms
set_privileges:      0.071 ms
get_auth:            0.001 ms

Trial #5
get_auth:            0.012 ms
get_auth:            0.005 ms
get_auth:            0.001 ms
get_auth:            0.000 ms
get_auth:            0.006 ms
set_privileges:      0.071 ms
get_auth:            0.002 ms

grant total:         0.475 ms (0.095 ms per trial)


***************************************************
*                                                 *
*  BENCHMARK RESULTS :: Minetest 0.4.16 Builtin   *
*                                                 *
***************************************************

-----------------
-- Player Join --
-----------------

Trial #1
on_prejoinplayer:     0.001 ms
get_auth:             0.016 ms
get_auth:             0.017 ms
get_auth:             0.022 ms
on_joinplayer:     4470.633 ms

Trial #2
on_prejoinplayer:     0.000 ms
get_auth:             0.009 ms
get_auth:             0.011 ms
get_auth:             0.004 ms
on_joinplayer:     5088.943 ms

Trial #3
on_prejoinplayer:     0.001 ms
get_auth:             0.009 ms
get_auth:             0.012 ms
get_auth:             0.004 ms
on_joinplayer:     4691.093 ms

Trial #4
on_prejoinplayer:     0.001 ms
get_auth:             0.01 ms
get_auth:             0.011 ms
get_auth:             0.003 ms
on_joinplayer:     4808.14 ms

Trial #5
on_prejoinplayer:     0.001 ms
get_auth:             0.009 ms
get_auth:             0.012 ms
get_auth:             0.004 ms
on_joinplayer:     4806.502 ms

grand total:      23865.468 ms (4773.094 ms per trial)

---------------------
-- New Player Join --
---------------------

Trial #1
on_prejoinplayer:   242.375 ms
create_auth:       4781.226 ms
get_auth:             0.010 ms
get_auth:             0.002 ms
on_joinplayer:     4871.191 ms

Trial #2
on_prejoinplayer:   274.661 ms
create_auth:       4876.873 ms
get_auth:             0.010 ms
get_auth:             0.003 ms
on_joinplayer:     4830.267 ms

Trial #3
on_prejoinplayer:   274.616 ms
create_auth:       5079.059 ms
get_auth:             0.010 ms
get_auth:             0.003 ms
on_joinplayer:     4688.667 ms

Trial #4
on_prejoinplayer:   281.815 ms
create_auth:       5106.088 ms
get_auth:             0.011 ms
get_auth:             0.003 ms
on_joinplayer:     4859.933 ms

Trial #5
on_prejoinplayer:   314.042 ms
create_auth:       4490.457 ms
get_auth:             0.014 ms
get_auth:             0.005 ms
on_joinplayer:     4873.050 ms

grand total:      49844.391 ms (9968.878 ms per trial)

--------------------
-- Set Privileges --
--------------------

Trial #1
get_auth:             0.018 ms
get_auth:             0.008 ms
get_auth:             0.004 ms
get_auth:             0.003 ms
set_privileges:    5112.665 ms
get_auth:             0.009 ms

Trial #2
get_auth:             0.017 ms
get_auth:             0.007 ms
get_auth:             0.004 ms
get_auth:             0.002 ms
set_privileges:    4678.318 ms
get_auth:             0.010 ms

Trial #3
get_auth:             0.022 ms
get_auth:             0.009 ms
get_auth:             0.004 ms
get_auth:             0.002 ms
set_privileges:    4772.478 ms
get_auth:             0.010 ms

Trial #4
get_auth:             0.021 ms
get_auth:             0.009 ms
get_auth:             0.003 ms
get_auth:             0.003 ms
set_privileges:    4752.323 ms
get_auth:             0.011 ms

Trial #5
get_auth:             0.020 ms
get_auth:             0.009 ms
get_auth:             0.003 ms
get_auth:             0.002 ms
set_privileges:    4820.505 ms
get_auth:             0.010 ms

grand total:      24136.500 ms (4827.300 ms per trial)


***************************************************
*                                                 *
*  BENCHMARK RESULTS :: Minetest 5.0 Builtin      *
*                                                 *
***************************************************

-----------------
-- Player Join --
-----------------

Trial #1
on_prejoinplayer:     0.290 ms
get_auth:             0.040 ms
get_auth:             0.053 ms
get_auth:             0.036 ms
on_joinplayer:       64.240 ms
get_auth:             0.075 ms
get_auth:             0.031 ms
get_auth:             0.029 ms
get_auth:             0.028 ms
get_auth:             0.025 ms
get_auth:             0.029 ms
get_auth:             0.029 ms

Trial #2
on_prejoinplayer:     0.075 ms
get_auth:             0.039 ms
get_auth:             0.046 ms
get_auth:             0.030 ms
on_joinplayer:       61.444 ms
get_auth:             0.057 ms
get_auth:             0.024 ms
get_auth:             0.023 ms
get_auth:             0.022 ms
get_auth:             0.020 ms
get_auth:             0.024 ms
get_auth:             0.024 ms

Trial #3
on_prejoinplayer:     0.078 ms
get_auth:             0.028 ms
get_auth:             0.047 ms
get_auth:             0.026 ms
on_joinplayer:       73.072 ms
get_auth:             0.058 ms
get_auth:             0.023 ms
get_auth:             0.020 ms
get_auth:             0.019 ms
get_auth:             0.019 ms
get_auth:             0.022 ms
get_auth:             0.033 ms

Trial #4
on_prejoinplayer:     0.077 ms
get_auth:             0.026 ms
get_auth:             0.048 ms
get_auth:             0.026 ms
on_joinplayer:       94.677 ms
get_auth:             0.056 ms
get_auth:             0.024 ms
get_auth:             0.021 ms
get_auth:             0.019 ms
get_auth:             0.019 ms
get_auth:             0.022 ms
get_auth:             0.023 ms

Trial #5
on_prejoinplayer:     0.076 ms
get_auth:             0.050 ms
get_auth:             0.045 ms
get_auth:             0.026 ms
on_joinplayer:       50.702 ms
get_auth:             0.058 ms
get_auth:             0.023 ms
get_auth:             0.020 ms
get_auth:             0.020 ms
get_auth:             0.019 ms
get_auth:             0.025 ms
get_auth:             0.023 ms

grand total:	    346.303 ms (69.260 ms per trial)

---------------------
-- New Player Join --
---------------------

Trial #1
on_prejoinplayer:   776.039 ms
create_auth:          0.008 ms
get_auth:             0.05 ms
get_auth:             0.028 ms
on_joinplayer:       60.969 ms
get_auth:             0.061 ms
get_auth:             0.023 ms
get_auth:             0.02 ms
get_auth:             0.019 ms
get_auth:             0.06 ms
get_auth:             0.025 ms
get_auth:             0.023 ms

Trial #2
on_prejoinplayer:   736.077 ms
create_auth:          0.008 ms
get_auth:             0.050 ms
get_auth:             0.025 ms
on_joinplayer:       52.891 ms
get_auth:             0.060 ms
get_auth:             0.022 ms
get_auth:             0.020 ms
get_auth:             0.019 ms
get_auth:             0.018 ms
get_auth:             0.022 ms
get_auth:             0.023 ms

Trial #3
on_prejoinplayer:   729.159 ms
create_auth:          0.008 ms
get_auth:             0.614 ms
get_auth:             0.028 ms
on_joinplayer:       74.917 ms
get_auth:             0.059 ms
get_auth:             0.023 ms
get_auth:             0.021 ms
get_auth:             0.033 ms
get_auth:             0.034 ms
get_auth:             0.024 ms
get_auth:             0.023 ms

Trial #4
on_prejoinplayer:   822.92 ms
create_auth:          0.007 ms
get_auth:             0.051 ms
get_auth:             0.026 ms
on_joinplayer:       65.927 ms
get_auth:             0.06 ms
get_auth:             0.024 ms
get_auth:             0.021 ms
get_auth:             0.019 ms
get_auth:             0.019 ms
get_auth:             0.022 ms
get_auth:             0.023 ms

Trial #5
on_prejoinplayer:   588.514 ms
create_auth:          0.007 ms
get_auth:             0.049 ms
get_auth:             0.025 ms
on_joinplayer:       57.614 ms
get_auth:             0.059 ms
get_auth:             0.022 ms
get_auth:             0.021 ms
get_auth:             0.02 ms
get_auth:             0.018 ms
get_auth:             0.022 ms
get_auth:             0.039 ms

grand total:       3967.030 ms (793.406 ms per trial)

--------------------
-- Set Privileges --
--------------------

Trial #1
get_auth:             0.085 ms
get_auth:             0.030 ms
get_auth:             0.039 ms
get_auth:             0.021 ms
set_privileges:      62.812 ms
get_auth:             0.056 ms

Trial #2
get_auth:             0.086 ms
get_auth:             0.032 ms
get_auth:             0.038 ms
get_auth:             0.023 ms
set_privileges:      63.765 ms
get_auth:             0.057 ms

Trial #3
get_auth:             0.084 ms
get_auth:             0.031 ms
get_auth:             0.034 ms
get_auth:             0.021 ms
set_privileges:      68.226 ms
get_auth:             0.057 ms

Trial #4
get_auth:             0.083 ms
get_auth:             0.031 ms
get_auth:             0.035 ms
get_auth:             0.021 ms
set_privileges:      56.744 ms
get_auth:             0.056 ms

Trial #5
get_auth:             0.084 ms
get_auth:             0.031 ms
get_auth:             0.033 ms
get_auth:             0.021 ms
set_privileges:      64.044 ms
get_auth:             0.055 ms

grand total:        316.735 ms (63.347 ms per trial)