Why svchost.exe is at 100% CPU simple solution

ref: http://bit.ly/1U4MdXQ

The SvcHost.exe process hosts services that run in the background on Windows. It’s literally “Service Host.” You may have a dozen services or more running inside that process. More complex is that you’ll sometimes see multiple SvcHost.exe’s in your TaskManager.

Let me tell you now, Task Manager will not save you. You can see the PIDs for a running Service for the Services tab, but when a service goes insane, good luck nailing it down.

This inevitably leads you to questions like, “What Services are running inside what SvcHost.exe?” and “Which Service is using 100% CPU.”

There’s lots of ways to figure this out, but first I’ll tell you that simply killing the SvcHost.exe process that is using the most CPU will also kill ALL the other services that were running inside that host process.

There’s many command line ways to figure this stuff out, like

net start

or

sc query type= service

or

tasklist /svc

But this post is about doing it the easy way without lining up Process IDs and such.

WHICH SERVICE IS FREAKING OUT?

From the Start Menu, type “Resource Monitor” and run it.

Resource Monitor

Click the checkboxes to the left of each of the svchost.exe processes (or just those that you care about). Now, switch to the CPU tab:

Resource Monitor - CPU

See the names of the logical services in the middle pane? Now you can sort by the CPU column and you’ve got the name of your out of control process.

You can right click and try to stop or restart just the one services, or even use default browser’s default search engine to “Search Online” for that service name:

Resource Monitor with the Right Click Menu showing

This tip has helped me several times while writing and debugging services. Resource Monitor is your friend. Many folks don’t’ even know it’s there!

Enjoy!

Advertisement

MySQL Remove Duplicates

If we have a table like that and want to remove rows with duplicate name fields.

+----+--------+
| id | name   |
+----+--------+
| 1  | google |
| 2  | yahoo  |
| 3  | msn    |
| 4  | google |
| 5  | google |
| 6  | yahoo  |
+----+--------+

1) If you want to keep the row with the lowest id value:

DELETE n1 FROM names n1, names n2 
WHERE n1.id > n2.id AND n1.name = n2.name

2) If you want to keep the row with the highest id value:

DELETE n1 FROM names n1, names n2 
WHERE n1.id < n2.id AND n1.name = n2.name

ref: http://stackoverflow.com/questions/4685173/delete-all-duplicate-rows-except-for-one-in-mysql

How to Update TeamCity Server

  1. Assumption is that you already have TeamCity installed (otherwise, why would you be looking to upgrade it 🙂
  2. Assumption is that you have already downloaded the new version of TeamCity, in this case 7.1.4.
  3. Log into TeamCity using an account that has Administrator privileges
  4. Click on the Backup link near the bottom left hand corner
  5. When the Run Backup Tab opens, click on “Start Backup”
  6. The backup should complete successfully
  7. Double Click the installation *.exe which was downloaded in Step 2 above
  8. At the first step in the installation wizard simply click Next
  9. Read the License Agreement and assuming you are happy with it, click “I Agree”
  10. In the “Choose Install Location” window, assuming you are happy with the default installation folder, simply click Next, otherwise change it first
  11. In order to install the latest version of TeamCity, you have to first uninstall the current version.  Click “Next”
  12. On this screen simply click Next once the current installation has been located
  13. Typically, since you are doing an upgrade, you want to keep both the build configuration and working directory, but the log files can be removed.  Click Uninstall
  14. The un-installation will continue
  15. After a short period, the un-installation will complete
  16. In the “Choose Components” window choose the components that you want to install.  As already mentioned, we will be installing both the Server and Build Agent on one server.  Click Next
  17. In the “Specify server configuration directory” window assuming you are happy with the default location click Next, otherwise change it first
  18. The main portion of the installation will start now
  19. The “Configure Build Agent Properties” window will then open, giving you the opportunity to add/edit build agent properties.  For now, you can leave this as the default.  If needed, this can be changed later.  Click Save.
  20. Simply click OK on the “TeamCity Build Agent Properties” pop-up
  21. In the “Select Service Account for Server” window decide what user account you want to run the TeamCity Server, I chose to use the SYSTEM account.  Click Next
  22. In the “Select Service Account for Agent” window decide what user account you want to run the TeamCity Build Agent, I chose to use the SYSTEM account.  Click Next
  23. In the “Services” window, choose to start both the Server and Build Agent Services, and click Next
  24. In the final screen, ensure that the option to open TeamCity Website after exit is checked and click Finish.
  25. A web page will open saying “TeamCity is starting”
  26. The login screen will then be presented
  27. On logging in, you will see the latest version number displayed

ref: http://www.gep13.co.uk/blog/how-to-upgrade-teamcity/

Linking folder on a path with Dropbox path

If there is folder, i.e. game save folder or sth. that you can’t move under Dropbox folder to continue working, then you can link a folder with dropbox folder to be in sync.

In windows there is a command named ‘mklink’ that enables linking folders.

Here is the usage

mklink [[/d] | [/h] | [/j]] <Link> <Target>

For example to link a game save folder with your dropbox folder:

mklink /D “C:\Users\username\Dropbox\games\My Favourite Game\” “C:\Program Files (x86)\Steam\steamapps\common\My Favourite Game\saves\”

This way your files will be always synced and also versioned with dropbox.

Note: Make sure “C:\Users\username\Dropbox\games\My Favourite Game\” folder does not exist, to allow mklink to create.

Note 2: If you get “Access Denied” error, try opening command prompt with Administrator rights.

Replacing jQuery live with on

.live() function is removed on jQuery version 1.9.

So if you want the same behaviour, you can use on with versions gte 1.9.

Let’s say we have a code that’s like:

$(“#serviceItemsContainer input“).live(“change”, function(){ /* some code */ });

then this code block can be changed like that:

$(“#serviceItemsContainer”).on(“change”, “input”, function(){ /* some code */ });

Notice, there is an extra parameter to pass the function as a selector. This way you can attach a function without having the item on DOM, when you execute the code.

Happy Coding

References:

https://api.jquery.com/live/

http://api.jquery.com/on/

http://weblog.west-wind.com/posts/2013/Jun/12/Replacing-jQuerylive-with-jQueryon

First and Second Level caching in Hibernate

1.1) First-level cache

First-level cache always Associates with the Session object. Hibernate uses this cache by default. Here, it processes one transaction after another one, means wont process one transaction many times. Mainly it reduces the number of SQL queries it needs to generate within a given transaction. That is instead of updating after every modification done in the transaction, it updates the transaction only at the end of the transaction.

1.2) Second-level cache

Second-level cache always associates with the Session Factory object. While running the transactions, in between it loads the objects at the Session Factory level, so that those objects will available to the entire application, don’t bounds to single user. Since the objects are already loaded in the cache, whenever an object is returned by the query, at that time no need to go for a database transaction. In this way the second level cache works. Here we can use query level cache also.

Source: http://www.javabeat.net/articles/37-introduction-to-hibernate-caching-1.htmlhttp://stackoverflow.com/questions/337072/what-is-first-and-second-level-caching-in-hibernate

Get Table Columns And Sizes

You can get SQL Server table columns and sizes with this query. Just change “___TABLE___NAME___” value with your table name.

 

CREATE TABLE #temp
(
colname varchar(50) NULL,
collen int NULL
)

INSERT INTO #temp (colname, collen)
SELECT column_name, character_maximum_length
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = ‘___TABLE___NAME___’
and data_type in(‘varchar’,’char’,’nvarchar’,’nchar’)

SELECT * FROM #temp

DROP TABLE #temp