Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' <summary>
- ''' This function generates and returns the values for a My.ini file for a LabTech server.
- ''' This function should be called during Server Creation or from within the UI and followed by writing the file restarting the MySQL server.
- ''' Each variable is done so for optimal performance using mathematical structures.
- ''' Comments before each variable explain the optimal math and pertinent information.
- ''' </summary>
- ''' <param name="MemoryInMB"> The value in MB of Memory allocated to the server.</param>
- ''' <remarks>
- ''' </remarks>
- Private Shared Function generateIniWithoutPaths(ByVal MemoryInMB As Integer) As String
- Dim temp As String = Nothing
- 'Populate our Name Value Collections once so that they're not repopulating for each action below.
- Dim serverVariables As NameValueCollection = LTSettings.MySQLInfo.ServerVariables
- Dim serverStatus As NameValueCollection = LTSettings.MySQLInfo.ServerStatus
- Dim innodbStatus As NameValueCollection = LTSettings.MySQLInfo.InnoDBEngineStatus
- 'Non Memory related or partial memory related variables.
- Dim innodblogfilesize As Integer = CInt(CInt(serverVariables.GetValues("innodb_log_file_size")(0)) / 1048576)
- Dim basedir As String = """" & CStr(serverVariables.GetValues("basedir")(0)) & """"
- Dim datadir As String = """" & Replace(CStr(serverVariables.GetValues("datadir")(0)), "/", "\") & """"
- Dim innodbdatahomedir As String = CStr(serverVariables.GetValues("innodb_data_home_dir")(0))
- ' Overhead memory buffers. These are fixed buffers that we don't change in size.
- ' With great power, and large memory buffers, comes great responsibility.
- ' Be careful when making changes to these variables.
- Dim sbuffersize As Integer = 2
- Dim jbuffersize As Integer = 4
- Dim rbuffersize As Integer = 4
- Dim rrbuffersize As Integer = 1
- Dim querycachesize As Integer = 64
- Dim innodbamempoolsize As Integer = 20
- Dim innodblogbuffersize As Integer = CInt(innodblogfilesize / 2)
- Dim MemOverheadTotals As Integer = sbuffersize + _
- jbuffersize + _
- rbuffersize + _
- rrbuffersize + _
- querycachesize + _
- innodbamempoolsize + _
- innodblogbuffersize
- ' Calculate the memory left for dynamic variables, less the overhead.
- Dim MemLessOverhead As Integer = MemoryInMB - MemOverheadTotals
- ' Dynamic memory buffers. These change based upon amount of resources available to the system.
- Dim msbuffersize As Integer = CInt(Math.Floor(MemLessOverhead * 0.05))
- Dim kbuffersize As Integer = CInt(Math.Floor(MemLessOverhead * 0.1))
- Dim innodbbufferpoolsize As Integer = CInt(Math.Round(MemLessOverhead * 0.7))
- Dim ttablesize As Integer = CInt(Math.Floor(MemLessOverhead * 0.15))
- 'for max_connections, always increment (never decrease) this number. The formula below ensures that.
- ' Max(Current maximum connections, max((max used connections + 10), (max used connections * 1.1))
- Dim max_connections As Integer = Math.Max(CInt(serverVariables.GetValues("max_connections")(0)), (Math.Max((CInt(serverStatus.GetValues("max_used_connections")(0)) + 10), (CInt(CInt(serverStatus.GetValues("max_used_connections")(0)) * 1.1)))))
- LTLogger.WriteLine("Memory for MySQL: " & MemoryInMB & "MB")
- temp = "[client]" & vbCrLf
- temp &= "port=3306" & vbCrLf
- temp &= "default-character-set=utf8" & vbCrLf & vbCrLf
- temp &= "[mysql]" & vbCrLf
- temp &= "default-character-set=utf8" & vbCrLf & vbCrLf
- temp &= "[mysqld]" & vbCrLf
- temp &= "port=3306" & vbCrLf
- temp &= "character-set-server=utf8" & vbCrLf
- temp &= "default-storage-engine=INNODB" & vbCrLf & vbCrLf
- temp &= "# It is not recommended to change these settings." & vbCrLf
- temp &= "skip-external-locking" & vbCrLf
- temp &= "transaction-isolation=REPEATABLE-READ" & vbCrLf
- temp &= "wait_timeout=900" & vbCrLf
- temp &= "interactive_timeout=7200" & vbCrLf
- temp &= "max_allowed_packet=1G" & vbCrLf
- temp &= "myisam_max_sort_file_size=10G" & vbCrLf
- temp &= "innodb_file_per_table" & vbCrLf
- temp &= "innodb_flush_log_at_trx_commit=2" & vbCrLf
- temp &= "innodb_log_files_in_group=2" & vbCrLf
- temp &= "innodb_thread_concurrency=0" & vbCrLf
- temp &= "innodb_log_file_size=" & innodblogfilesize & "M" & vbCrLf
- temp &= "innodb_log_buffer_size=" & innodblogbuffersize & "M" & vbCrLf
- temp &= "tmp_table_size=" & ttablesize & "M" & vbCrLf & vbCrLf
- temp &= "## These settings total to equal MySQL's memory usage. Use caution when modifying." & vbCrLf
- temp &= "## Setting them too high can mean your MySQL server won't start." & vbCrLf
- temp &= "key_buffer_size=" & kbuffersize & "M" & vbCrLf
- temp &= "myisam_sort_buffer_size=" & msbuffersize & "M" & vbCrLf
- temp &= "read_buffer_size=" & rbuffersize & "M" & vbCrLf
- temp &= "read_rnd_buffer_size=" & rrbuffersize & "M" & vbCrLf
- temp &= "sort_buffer_size=" & sbuffersize & "M" & vbCrLf
- temp &= "join_buffer_size=" & jbuffersize & "M" & vbCrLf
- temp &= "innodb_additional_mem_pool_size=" & innodbamempoolsize & "M" & vbCrLf
- temp &= "query_cache_size=" & querycachesize & "M" & vbCrLf & vbCrLf
- temp &= "# This setting is part of the memory total, but should be modified if performance is slower." & vbCrLf
- temp &= "# The biggest performance gains you can get are by setting innodb_buffer_pool_size" & vbCrLf
- temp &= "# equal to the size of your database." & vbCrLf
- temp &= "#" & vbTab & "(as long as you have the free memory)" & vbCrLf
- temp &= "innodb_buffer_pool_size=" & Math.Min(8192, innodbbufferpoolsize) & "M" & vbCrLf & vbCrLf
- ' Done memory usage variables. Begin editable variables.
- temp &= "# These variables should be increased if performance is slower." & vbCrLf
- temp &= "max_connections=" & Math.Max(300, max_connections) & vbCrLf
- temp &= "table_open_cache=" & (max_connections * 2) & vbCrLf
- temp &= "thread_cache_size=32" & vbCrLf & vbCrLf
- 'MySQL version specific section.
- If CDbl(Left(serverVariables.GetValues("Version")(0), 3)) > 5.1 Then
- ' MySQL 5.5 and above.
- temp &= "# These variables are for MySQL 5.5 and above only" & vbCrLf
- temp &= "innodb_read_io_threads=32" & vbCrLf
- temp &= "innodb_write_io_threads=24" & vbCrLf & vbCrLf
- If Math.Round(MemoryInMB * 0.6) > 1024 Then
- temp &= "innodb_buffer_pool_instances=" & Math.Floor(innodbbufferpoolsize / 1024) & vbCrLf & vbCrLf
- End If
- ElseIf CDbl(Left(serverVariables.GetValues("Version")(0), 3)) <= 5.1 Then
- temp &= "# These variables are for MySQL versions 5.1 and below only" & vbCrLf
- temp &= "innodb_file_io_threads=32" & vbCrLf & vbCrLf
- Else
- Throw New InvalidOperationException("The version was unknown. Please run this on the LabTech server.")
- End If
- ' Directories for the Install - Use whatever was already in place.
- temp &= "# These are the paths to where the MySQL data is stored." & vbCrLf
- temp &= "basedir = " & basedir & vbCrLf
- temp &= "datadir = " & datadir & vbCrLf
- If Not innodbdatahomedir = "" And innodbdatahomedir IsNot Nothing Then
- temp &= "innodb_data_home_dir= """ & innodbdatahomedir & """" & vbCrLf
- End If
- Return temp
- End Function
Add Comment
Please, Sign In to add comment