Friday, May 25, 2018

Load multiple javascript/js files from one javascript file

Sometimes there are several javascript files used to include in a project. but js file could be a small file. It's good practice if we use less file in a web project. So, in that case, we can load multiple javascript/js files from one javascript file.

Example
<footer>
<script type="text/javascript" src="jsfile1.js"></script>
<script type="text/javascript" src="jsfile2.js"></script>
<script type="text/javascript" src="jsfile3.js"></script>
</footer>
We need to make a function example function name include also this function will use that single js file where we can call other js files.
Code for the single js file (single.js)
function include(jspath) {
    document.write('<script type="text/javascript" src="'+jspath+'"><\/script>');
}

include("jsfile1.js");include("jsfile2.js");include("jsfile3.js");
Now we can call just one single js file where other 3 js file already include
<footer>
<script type="text/javascript" src="single.js"></script>
</footer>

One important thing to remember that if we need to use the function or this code to combine js file
document.write('<script type="text/javascript" src="jsfilepath.js"><\/script>');

some js file may not work if we use this jquery method.
$.getScript("includes/tableExport/jspdf/jspdf.js", function(){});



Sunday, May 20, 2018

MySQL Performance Tuning

When MySQL becomes too slow (or too unstable), temptation usually is to tweak the MySQL configuration file. Indeed, it’s a good place to start. But if you ever looked at the available configuration options, you know things can get messy – MySQL now has over 450 configuration variables for your consideration, that are not classified in any way, and neither of them is included in the stock my.cnf.

We can setup/change default MySQL setup value by two methods.
1. using MySQL cmd / phpmyadmin which is the temporary solution. after restarting MySQL server all setup will change to the default value.

2. using the changing mysql config file name my.cnf  vis ssh
To edit the MySQL settings with my.cnf file type the following command. 

nano /etc/my.cnf

Find the settings you wish to edit. Say, for example, you want to increase the max_connections limit for MySQL server. Locate max_connections and set your desired value.

max_connections=20

To increase the max_connectionsto 30 change it to the following.

max_connections=30

Enter Ctrl + O to save the settings and Ctrl + X to exit. Restart the MySQL server by typing the following command.

service mysql restart

What does it mean the process "Sleep"?

There is a lot of connection seeing sleep. It's not a query waiting for a connection; it's a connection pointer waiting for the timeout to terminate.

It doesn't have an impact on performance. The only thing it's using is a few bytes as every connection does. But if it crosse max_connection limit then MySQL will trigger error "Too many connections"

It'll better to kill "sleep" connections. By default connection still alive / stay in task list up to 8 hours


mysqld will timeout database connections based on two server options:
Both are 28,800 seconds (8 hours) by default.
You can set these options in /etc/my.cnf
If your connections are persistent (opened via mysql_pconnect) you could lower these numbers to something reasonable like 600 (10 minutes) or even 60 (1 minute). Or, if your app works just fine, you can leave the default. This is up to you.
You must set these as follows in my.cnf (takes effect after mysqld is restarted):
[mysqld]
interactive_timeout=180
wait_timeout=180
We can check from directly MySQL using this command
show variables like "interactive_timeout"
If you do not want to restart MySQL, then run these two commands:
SET GLOBAL interactive_timeout = 180;
SET GLOBAL wait_timeout = 180;
This will not close the connections already open. This will cause new connections to close in 180 seconds automatically.





Total Pageviews