8 steps to speed up slow Windows

Your system worked well. Then, one day, the startup after login is very slow and you cannot figure out why. There are 4 diagnosis steps and 8 steps to follow to make your PC faster in these cases.

Diagnosis

  1. Windows orb > Search for “event”
  2. Click on “Event viewer”
  3. Take a look to critical and errors
  4. Go to Administrative events and explore errors to look for malfunctioning drivers or applications

How to fix

  1. Download Autoruns for Windows by Microsoft
  2. Extract Autoruns and enter the directory
    1. Right click on Autoruns64.exe (Autoruns.exe on 32 bit systems)
    2. Run as administrator
  3. Click on the Logon tab
  4. Remove check from all entries you think are slowing down the system
  5. Click on Services tab
  6. Remove check from all services you think are slowing down the system: be aware that some services are essential to some applications so if you don’t need them you have to unistall the application to avoid malfunctions
  7. Do not touch the driver tabs! Disabling the wrong driver you can compromise your system
  8. If you have more than one antivirus software, e.g Avira and Microsoft Security Essential update the one you want to keep and uninstall the other in order to avoid conflicts

Disable any application or services you don’t need, uninstall unwanted or malfunctioning applications, restart the system and check the time elapsed after login and the Event viewer.

If you think a USB device is the culprit you can try USB Oblivion to remove unused USB drivers.

Usually you can solve many issues this way but if you haven’t you can try a strongest method using an utility disk.

Tested on:

  • Windows 7
Advertisements

How to fix freezed Windows 7

If your Windows system is slow and you’ve already tried to clean up the autostarts you may have other issues. To do a global check on your system you can follow these steps:

  1. Download Hiren’s Boot CD (list of software installed here)
  2. Extract the zip file in a new folder (the zip contains many files)
  3. Use the shipped CD creation tools BurnCDDC or use the excellent cdrtools Frontend going to CD image > Write image and choosing the Hiren’s.BootCD.x.x.iso file inside
  4. Restart the PC with the CD in and boot from disk: after the boot a screen will be presented, usually you have to press a key like F12 to choose a boot device or press a key like F2 to go to BIOS and choose the boot order putting the DVD first
  5. Choose Start Mini Windows XP and press Enter
  6. After boot, you’ll see an interface similar to Windows XP: on Desktop click on My Computer to view if all drives are listed. Take a look at the space left on devices
  7. Start > Programs > Check disk, insert the letter of the drive to check and then Enter
  8. (Optional) After the disk check, you can also use other disk tools from Desktop > HBCD Menu > Programs > Hard disk tools if needed. Be careful, some tools can be dangerous and you have to know what you’re doing
  9. Now that disk error are fixed, go to Desktop > HBCD Menu > Programs > Antivirus/Spyware and choose Avira or Malawarebytes’ Anti-Malaware
  10. Choose the units and the scan mode and then run the tool
  11. Repeat these steps with all tools you need in the Antivirus / Spyware section
  12. Go to Desktop > HBCD Menu > Programs > Cleaners > CCleaner or ATF Cleaner and clean temporary files and entries from your system. Warning: personal data like browser saved password could be lost, choose the cleaning options carefully
  13. On Desktop > HBCD Menu > Programs > Cleaners > MyUninstaller uninstall all application you don’t need
  14. Check the space left on the disks on Desktop > My Computer. If little space is left on the main drive use Desktop > HBCD Menu > Programs > Cleaners > Windirstat to find big files (about Windirstat)
  15. Now it’s time to look at the apps in autostart: go to Desktop > HBCD Menu > Programs > Startup tools > Autoruns: this is a Microsoft app that lists all application executed automatically. Look for suspicious entries and disable what you don’t need
  16. You can explore other tools on this bootable CD depending on your needs

Tested with Hiren’s BootCD 15.2

Screencapture to GIF: how to record desktop and save screencast as animated GIF

This is a step-by-step howto to record your desktop and then save it as animated GIF using free software. The resulting file will be very small compared to video files, e.g. a 2 minutes long screencapture of a webpage browsing can be less than 1MB.

Requirements:

  • Windows
  • CamStudio
  • VirtualDub
  • Gimp
  • Gigabytes of free space in the destination drive for the intermediate video screencapture

How to:

  1. Install CamStudio
  2. Install VirtualDub (if you have a 64bit OS install the 64 bit version)
  3. Prepare the window you have to screencapture
  4. Capture the video
    1. Open CamStudio
    2. Options > Video Options > Codec Intel IYUV (lossless) and then OK
    3. Select Region > Windows (or other as needed)
    4. Press the record button and select the Window to record
    5. Press stop to stop recording
    6. Select a destination directory and filename: make sure you’ve enough free space
  5. Convert to GIF
    1. Decompress VirtualDub and launch the Veedub64.exe (user interface) or equivalent
    2. File > Open video file and then select the previously generated file (step 4.6)
    3. Video > Frame rate > Frame rate conversion
    4. Select Convert to fps and specify a low value like 2 and then OK
    5. Video > Color Depth
    6. From Output format to compressor / display select 16 bit RGB (555) or greyscale (0-255): it will downsize the output GIF file
    7. File > Export > Animated GIF
    8. Select Play once, infinite loop or specify a loop number
    9. Save the resulting file
  6. Edit the GIF
    1. Launch GIMP
    2. Optional: Select Window > Single window mode to keep all tools in one window (useful for PhotoShop users)
    3. Open the generated GIF (step 5.9)
    4. Crop, rescale and alter the image as you like
    5. Optional: Image > Mode > Indexed to change colors reducing filesize
    6. File > Export as… > Animated GIF
    7. Check the “As animation” flag
    8. Export

The GIF can now be published on forums, WordPress.com or any image hosting provider.

PuTTY freezes on OpenVPN on Windows

Issue: Opening PuTTY no login information are returned and then the connection is closed.

Solution (Windows 7):

  1. On the taskbar Right click and then Disconnect the VPN
  2. Look for the VPN icon and then Right click on VPN shortcut icon > Properties
  3. Select Compatibility tab and then check Run as administrator
  4. Launch OpenVPN: a message will be prompted to allow the app to run as administrator

Stop to send Microsoft information about your system

These steps will help you to block some of error reporting to Microsoft.

To help you in the task of finding error reporting issues install and run the free Kaspersky Security Scan: you will be notified by a list of issue affecting the PC the other antivirus usually don’t tell.

One of it is the notification to Microsoft of system states in situations like crashes. To stop sending Microsoft information like this you can follow these steps.

  1. On Windows 7, search “Action Center” in Windows > Search (or in your language, e.g. “Centro operativo” in Italian)
  2. Go to the 2nd voice on the left bar “change settings”
  3. Go to 2nd voice of related settings about error notification
  4. Check the very last element (Never check for solutions)
  5. In the previous screen check the first element about software use is disabled

Now take care about Microsoft Internet Explorer:

  1. On Windows 7, Run gpedit.msc
  2. Go to User Configuration > Administrative Templates > Windows Components > Internet Explorer
  3. Double click on Turn off Crash detection and then “Enable”
  4. Under Browser Menu Disable “Turn off the ability to launch report site problems using a menu option”

If you don’t use Internet Explorer as your main browser, disable also this under User Configuration > Administrative Templates > Windows Components > Internet Explorer:

  1. On the starting page option, check disable and set starting page as about:blank
  2. Run Internet Explorer and confirm the dialog about the about:blank as default page
  3. Now standard user cannot change the default starting page

Now go to Internet Explorer:

  1. Go to Gear (top right on IE 11) > Internet Options > Advanced > Security
  2. Select “Do not save crypted pages on disk”

Now go to Kaspersky Security Scan, go to Reports and refresh the list of issue. Note that if you have an antivirus, like Avira, Kaspersky will tell you autorun are active even if Avira block it so you can ignore these warning in this case.

A typical web application

Reduce Time to the First Byte – TTFB on web applications

How to speed up the time to the first byte and what are the causes of a long TTFB? Main causes are network and server-side and I will focus on server-side causes. I’m not covering any CMS here but you can try to apply some of these techniques starting from how to interpret the browser Timing.

Get reliable timing

Take a website with cache enabled: at the 9th visit on a page you can be sure your page is in cache, the connection with the webserver is alive, the SSL/TLS connection is established, the SQL queries are cached and so on. Open the network tab and enjoy your site speed: well, very few real users will experience that speed.

Here a comparison of a first time, no-cache connection to a nginx webserver explored with Chrome (F12 > Network > Timing) and a second request with the same page refreshed right after the first:

performance-01

I got a +420% on a first time request compared with a connected-and-cached case. To obtain a reliable result (1st figure) you should usually:

  • Wait several seconds after a previous call before doing anything, waiting for the webserver to close connection with the client
  • Add a ?string to the url of the page you’re visiting. Change the string every time you want a fresh page.
  • Ctrl+shift+R to reload the page

This technique bypass the Django view cache and similar cache systems on other framework. To check the framework cache impact, do a Ctrl+shift+R just after the first request obtaining a similar result of the 2nd figure. There are better ways to do the same, this is the easiest.

Break up the time report

Unpack the time report of the first-time request:

  • Connection setup (15% of the elapsed time in the example)
    • Queueing: slight, nothing to do.
    • Stalled: slight, nothing to do.
    • DNS lookup: slight, nothing to do.
    • Initial connection: significant, skip for now.
    • SSL: significant, client establish a SSL/TLS connection with the webserver. Disabling ciphers or tuning SSL can reduce the time but the priority here is best security for the visitor, not pure speed. However, take a look at this case study if you want to tune SSL/TLS for speed.
  • Request / response (85% of the elapsed time i.e.)
    • Request sent: slight, browser-related, nothing to do.
    • Waiting (TTFB): significant, time to first byte is the time the user wait after the request was sent to the web server. The waiting time includes:
      • Framework elaboration.
      • Database queries.
    • Content Download: significant, page size, network, server and client related. To speed up content download of a HTML page you should add compression: here an howto for nginx and for Apache webservers: these covers proxy servers, applying directly on a virtualhost is even simplier and the performance gain is huge.

Not surprisingly, the time of a first time request is elapsed most in Request / response than on connection setup. Among the Request / response times is the Waiting (TTFB) the prominent. Luckyly it is the same segment covered by cache mechanics of the framework and consequently is the most eroded passing from the first (not cached) to the second figure (cached by the framework). To erode the TTFB, database queries and elaboration must be optimized.

Optimize elaboration: program optimization

When Google, the web-giant behind the most used web search engine in history, try to suggest some tips to optimize PHP to programmers they react badly starting from daily programmers going up to the PHP team bureau.

In a long response, the PHP team teach Google how to program the web offering unsolicited advice offering “some thoughts aimed at debunking these claims” with stances like “Depending on the way PHP is set up on your host, echo can be slower than print in some cases”, a totally confusing comment for a real-world programmer.

Google put offline the PHP performance page that can be misleading but still contains valid optimization tips, especially if you compare with some of comments on php.net itself. Google have interests to speed and code optimization and the writer has the know-how to talk about it, the PHP team here just want to be right and defend their language and starting from good points crossed the line of scientific dialectic.

Program optimization mottos are:

Look for the best language that suits to your work and the best tools you can and look for programmers from the real-world sharing their approaches to the program optimization.

PHP team’s whining will not change the fact that avoiding SQL inside a loop like Google employee suggested is the right thing to do to enhance performance. This leads to database optimization.

Dude, where is my data?

The standard web application nowadays has this structure:

A typical web application

A typical web application: application server run the application so from now on  – oversimplifying – I will treat application and application servers as synonyms.

After the client requests pass through the firewall, webserver serve static files and ask to Application server the dynamic content.

Cache server can serve application or web server but in this example the earlier has the control: an example of cache controlled by application is on the Django docs about Memcache, an example of cache by web server is the HTTP Redis module or the standard use of Varnish cache.

Database server (DBMS) stores the structured data for the application. DBMS on standard use cases can be optimized with little effort. More difficult is to optimize the way the web application get the data from the database.

Database query optimization: prefetch and avoid duplicates

To optimize database queries you have to check the timing, again. Depending on the language and framework you are using there are tools to get information about queries to optimize:

Since I’m using Python I go with Django Debug Toolbar, a de-facto standard for application profiling. Here a sample of SQL query timing on a PostgreSQL database:

Timing of SQL queries on Django Debug Toolbar.

Timing of SQL queries on Django Debug Toolbar.

The total time elapsed on queries is 137,07 milliseconds, the total number of queries executed are 90. Among these, 85 are duplicates. Below any query you’ll find how many times the same query is executed. The objective is to reduce the number of queries executed.

If you’re using Django, create a manager for your models.py to use like this:

class GenericManager(models.Manager):
    """
    prefetch_related: join via ORM
    select_related: join via database
    """
    related_models = ['people', 'photo_set']
    def per_organizer(self, orgz, **kwargs):
        p = kwargs.get('pubblicato', None)
        ret = self.filter(organizer = orgz)
        return ret

class People(models.Model):
    name = models.CharField(max_length=50)
    ...

class Party(models.Model):
    organizer = models.ForeignKey('People')
    objects   =  GenericManager()

class Photo(models.Model):
    party = models.ForeignKey('Party')
    ...

Then in views.py call your custom method on GenericManager:

def all_parties(request, organizer_name):
    party_organizer = People.objects.get(name=organizer_name)
    all_parties = Party.objects.per_organizer(party_organizer)
    return render(request, 'myfunnywebsite/parties.html', {
        'parties' : all_parties
    })

When you want to optimize data retreival for Party, instead of comb through objects.filter() methods on views.py you will fix only the per_organizer method like this:

class GenericManager(models.Manager):
    """
    prefetch_related: join via ORM
    select_related: join via database
    """
    related_models = ['people', 'photo_set']
    def per_organizer(self, orgz, **kwargs):
        ret = self.filter(organizer = orgz)
        return ret.prefetch_related(*self.related_models)

Using prefetch_related queries are grouped via ORM and all objects are available, avoiding many query duplicates. Here a result of this first optimization:

django_sql_query_debug_toolbar_2

  • Query number is dropped from 90 to 45
  • Query execution time dropped from 137,07 to 80,80 (-41%)

An alternative method is select_related, but in this case the ORM will produce a join and the above code will give an error because photo_set is not accessible in this way. If your models are structured in a way you got a better performance with select_related go with it but remember this limitation. In this use case the results of select_related are worse than prefetch_related.

Recap:

  • TTFB can be a symptom of server-side inefficiency but you have to profile your application server-side to find out
  • Check SQL timing
  • Reduce the number of queries
  • Optimize application code
  • Use cache systems, memory-based (redis, memcached) are the faster

In my experience, inefficient code and a lot of cache are a frail solution compared with the right balance between caching and query + program optimization.

If you’ve tried everything and the application is still slow, consider to rewrite it or even to change the framework you’re using if speed is critical. When any optimization failed, I went from a Drupal 6 to a fresh Django 1.8 installation, and Google understood the difference in milliseconds elapsed to download the pages during indexing:

downloadtime

Since you can’t win a fight with windmills, a fresh start may be the only effective option on the table.

How to find big files on disk

On Windows: WinDirStat

  • Download and install WinDirStat
  • Run WinDirStat on your disks (it will take time)
  • You’ll see a coloured map of file occupation by file type

windirstat

On Linux command line: ncdu

  • On Ubuntu / Debian
    • apt-get install ncdu
    • cd /dir/to/check
    • ncdu
  • On CentOS / Fedora / RedHat
    • yum install ncdu
    • cd /dir/to/check
    • ncdu
ncdu-screenshot

ncdu screenshot by dev.yorhel.nl: Official Website

On Linux with window manager

  • CentOS / Fedora / RedHat
    • apt-get install k4dirstat
  • On Ubuntu / Debian
    • yum install k4dirstat

Again, you’ll see a coloured map of file occupation by file type.

Official website

 

dirstat1-yuenhoe

Screenshot by yuenhoe.com