I am dealing with a CakePHP project. Recently I added UnitTests to the project. My system Configuration is:
PHPUnit 3.7.24.
Cake Versio 2.4.2.
VM Server with a 4 Core Intel(R) Xeon(R) CPU E5-2609 v2 # 2.50GHz
9.1-RC3 FreeBSD.
But one of my tests is running very slow. It needs ~ 37 minutes to be finished. I am using 10 fixtures in this test but I don't load records them from another database,
thus my Fixture Classes contain only this line:
public $import = array('model' => 'Model', 'records' => false);
The test contains three testAction()-calls. Two of them run fast, the third one doesn't. The third call runs a controller action which does the following:
run two find-queries on a tables with ~ 2 entries
get the webvserver ip with ifconfig
connect to another vm per ssh (with phpseclib)
copy a 3,6 MB file with scp from webserver to vm
run a python script
copy it's json output back to the webserver
save the json information in the webserver's database (< 40 table entries)
remove the python script results on the vm
When I run the same controller action by clicking on an Icon in the webinterface, then it finishes after < 1 mniute. But running it per testAction() within the unit test
takes ~ 37 minutes, as I told.
I've already tried to set Configure::write('debug', 0);, without any effect.
I ran the test in the console per "cake test" command, without any performance boost.
I dereased Model->recursive as much as I could to get all information
Any idea how to fasten this UnitTest? My other UnitTests only take < 1 minute.
You need to profile each operation in that test in a log file so you will know where the problem is.
Use PHP's microtime() function to measure things precisely.
Also it's a very good practice to use log files to monitor what is going on and to get rough estimates of how much operations take. Such a log file will show you immediately where the bottleneck is...
So I recommend you setup logging and if you need precise timing use the microtime() function.
This is NOT a unit testing. You are testing network connection, bash (or whatever) interpretator and database. UnitTest MUST test only one unit of code - usually class. You must not use network or database. If you testing sequience of action class should take - use mock objects and expectations of method class.
Related
I wanted to try out integration of Selenium Jmeter and StormRunner. My end goal is to do Load testing with 'n' number of users on StormRunner
What ? - For e.g. I have Selenium Script, convert it in to Jmeter (I can get this information from many sources)
Then my Jmeter script should get ready
Then upload Jmeter script in to StormRunner and pass the necessary parameter through Jenkins and run the load test.
I really want the opinion here about feasibility and whether it is in right direction or not.
Idea here is that Automated Load/Performance test
Selenium is a browser automation framework and JMeter acts on HTTP protocol level so your "Automated" requirement might not be fulfilled especially if your tests are relying on client-side checks like sorting or waiting for element to appear.
Theoretically given you properly configure JMeter it can behave like a real browser, but it still not be executing client-side JavaScript.
If you're fine with this constraint - your approach is valid, if not and the "automated functional test" requirement is the must - consider migrating to TruClient Protocol instead
Why wouldn't you covert your script to a native Loadrunner/Stormrunner form of virtual user?
You should look at the value of what you are trying to achieve. The end value of a performance test is in analysis. Analysis simply takes the timing records and the resource measurements produced during the test, bringing them together on a common timestamp, and then allowing you to analyze what resource "X" is being impinged when timing record "Y" is too long. This then points to some configuration or code which locks up on resource, "X."
What is your path to value in your model? You speak about converting a functional test script to a performance one. Realistically, you should already know that your code, "works for one," before you get to asking, "Does it work for many?" There is a change in script definitions which typically accompanies this understanding.
Where are your collection of resources noted? Which Resources? On which Hosts? This is on the "path to value" problem where you need to have the resource measurements to diagnose root cause of poor performance.
So I'm learning about Spark and I have a question about how client libs works.
My goal is to do some sort of data analysis in Spark, telling it where are the data sources (databases, cvs, etc) to process, and store results in hdfs, s3 or any kind of database like MariaDB or MongoDB.
I though about having a service (API application) that "tells" spark what I want to do. The question is: Is it enough setting the master configuration with spark:remote-host:7077 at context creation or should I send the application to spark with some sort of spark-submit command?
This completely depends on how your environment is set up, if all paths are linked to your account you should be able to run one of the two commands, to efficiently open the shell and run test commands. The reason to have a shell, is this will allow you to dynamically run commands and validate/learn how to run/tether commands onto one another and see what results come out.
Scala
spark-shell
Python
pyspark
Inside of the environment, if everything is linked to Hive tables you can check the tables by running
spark.sql("show tables").show(100,false)
The above command will run a "show tables" on the Spark-Hive-Metastore Catalogue and will return all active tables you can see (doesn't mean you can access the underlying data). The 100 means I am going to look at 100 rows and the false means to show the full string not the first N many characters.
In a mythical example if one of the tables you see is called Input_Table you can bring it into the environmrnt with the below commands
val inputDF = spark.sql("select * from Input_Table")
inputDF.count
I would heavily advise, while your learning, not to run the commands via Spark-Submit, because you will need to pass through the Class and Jar, forcing you to edit/rebuild for each testing making it difficult to figure how commands will run without have a lot of down time.
I have an EF 6.2 project in my MVC solution.
This uses a SQL server db and has about 40 tables with many foreign keys.
The first query is very slow, 20 secs.
I immediately hit the same page again, changing the user param, and the query takes less than 1 second.
So this looks like a warm up issue in EF6. That's fine and there's loads of things i can do to sort apparently.
The Model cache (part of EF6.2) looks like it could be beneficial, but everywhere i read about it states model first. Nothing about DB first. Would this still work with db first?
Also there's the Entity Framework 6 power tools, these allow for me to Generate Views. Tried this and it doesn't seem to make any difference. Is this still a valid route?
Any other ideas?
EF DbContexts incur a one-off cost to resolve their entity mappings. For web applications you can mitigate this by having your application start up kick off a simple query against the DbContext which "kicks off" this warm-up rather than during your first user-triggered query. Simply new-ing up a context doesn't trigger the initialization, running a query does. So for ASP.Net MVC on the Application_Start, after initializing everything:
using (var context = new MyContext())
{
var warmup = context.MyTable.Count(); // against a small table.
}
You can test this behaviour with unit tests by having a suite of timed tests that read data from the DbContext, and putting a break-point in DbContext's OnModelCreating event. It will be executed just once from the first test with the first query. You can add a OneTimeSetUp in a test fixture setup to run ahead of the tests with the above quick count example to incur this cost before measuring the performance of the test runs.
So, the answer was to update EF to 6.2 then use the newest feature:
public class MyDbConfiguration : DbConfiguration
{
public MyDbConfiguration() : base()
{
var path = Path.GetDirectoryName(this.GetType().Assembly.Location);
SetModelStore(new DefaultDbModelStore(path));
}
}
for the full story check out this link: https://entityframework.net/why-first-query-slow
Your gonna take a small performance hit at startup but then it all moves a lot faster.
For anyone using an Azure web app you can use a deployment slot (https://stackify.com/azure-deployment-slots/), this allow you to publish into a non-production slot then warm it up before swapping it in as the production slot.
I have developed a shiny app, first have to run SQL queries which need around 5-10 minutes to be ran. The building of the plots afterwards is quite fast.
My idea was to run the queries once per day (with invalidLater) before shinyServer(). This worked well.
Now I got access to a shiny server. I could save my app in ~/ShinyApps/APPNAME/ and access it by http://SERVERNAME.com:3838/USER/APPNAME/. But if I open the app, while it is not open in some other browser it takes 5-10 min to start. If I open it, while it is also open on another computer it starts fast.
I have no experience with severs, but I conclude my server only runs the app as long someone is accessing it. But in my case it should be run permanently, so it always starts fast and can update the data (using the sql queries) once per day.
I looked up in the documentation, since I guess it is some setting problem.
To keep the app running:
Brute force: You can have a server/computer, have a view of your app open all the time so it does not drop from shiny server memory. but that won't load new data.
Server settings: you can set the idle time of your server to a large interval, meaning it will wait that interval before dropping your app from memory. This is done in the shiny-server.conf file with fx. app_idle_timeout 3600
To have daily updates:
Crontab:
Set up a crontab job in your SSH client fx. PuTTY:
$ crontab -e
like this(read more: https://en.wikipedia.org/wiki/Cron):
00 00 * * * Rscript /Location/YourDailyScript.R
YourDailyScript.R:
1. setwd(location) #remember that!
2. [Your awesome 5 minute query]
3. Save result as .csv or whatever.
and then have to app just load that result.
I am currently running Icinga1 to monitor around ~6000 services.
On the Icinga dashboard, I see that the average check time is ~ 300 s, which means some of my checks are running slow. Unfortunately , because there are 6000 checks I don't have a way to figure out all the checks that are running for more than a sec.
Is there a way to figure out the checks which run for more than a certain duration(say 5 sec) either from the classic UI or from the logs.
Try the wiki - performance tuning with Icinga1 is a big topic over there.
https://wiki.icinga.org/display/howtos/Identify+long+lasting+checks
I figured out that it using the icinga.cfg you can write host and service check performance data to files in custom formats.
Documentation for host performance data
Documentation for service performance data
You can also setup pnp4nagios to read this info and convert it into graphical reports.
You can consider using "crontab" to make the checks on different times to lower the use of the system.
Read more about crontab here - http://www.adminschoice.com/crontab-quick-reference