Skip to main content

Posts

Showing posts from 2011

Problem with Primary key as an Integer

We all know that any good database design has a unique primary key. Now point is how to decide, whether our primary key should be integer or not ? Well, primary key as an Integer works well with local systems and easy to use and also works great while writing manual SQL statements. But what if one is not working on local system and working in a distributed environment where one has to deal with replication scenarios. In such scenarios, Integers can't be primary key as they have state (sequencing) and can become a major security threat. Now here system demand for something unique apart from integers. And here comes GUID into picture, which provides globally unique id. You might be thinking that, is it a good choice to use 16 bytes of primary key instead of 4 bytes, then my answer will be definitely YES only when sync'ing is required. Using GUID as a row identity feels more truely unique and databse guru Joe seems to agree. But again performance issues arises in various scenarios

Reducing flicker, blinking in DataGridView

One of my project requirement was to create a Output Window similar to Visual Studio. For that I used a DataGridView. But when I start my application , I found that there is lot of blinking, flicker, pulling... After badly hitting my head with google, I found a very easy way. We just need to create a extension method to DataGridView and it's all done: public static void DoubleBuffered(this DataGridView dgv, bool setting) {     Type dgvType = dgv.GetType();     PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",           BindingFlags.Instance | BindingFlags.NonPublic);     pi.SetValue(dgv, setting, null); } CodeProject

Overview of CDN

CDN (Content Delivery Network) A computer network which has multiple copies of data stored at different points of the network.   The end user connected to a CDN will access the data from the nearest server (middle) instead of connecting to a Central server.   Few of the applications include media distribution, multiplayer gaming, and distance learning.   The end user can be a wired or wireless unit, which tries to access the content. The middle servers (or several servers forming a cluster) store the images of the content from the central (main) server. They are located at the edge of the ISP network and may be geographically separated from each other. Elements of CDN Request: A request for a specific content (for e.g. a webpage) is made from the End user, which is redirected to the nearest image server. This is done by the use of a protocol known as Web Cache Communication Protocol (WCCP).   Distribution: Once the request is received, a distribution element

Improving application start up time having signed assemblies

I guess all are aware that signed assemblies need verification from CA. This verification can create panic, when certification authority is not present on the same machine. In that case, assemblies require internet access. Situation can be more problematic, if there is no internet or network access on that machine. In absence of network access .Net thread might timeout waiting to connect. This issue can be avoided by adding following setting in machine.config: <configuration>     <runtime>         < generatePublisherEvidence enabled="false" />     </runtime>  </configuration>

Security concerns with serialization

Serialization can allow other code to see or modify object instance data that would otherwise be inaccessible. Therefore, code performing serialization requires the SecurityPermission attribute from System.Security.Permissions namespace with the SerializationFormatter flag specified. The GetDataObject method should be explicitly protected to help protect your data.

Inner workings of Deserialization

Within the runtime, deserialization can be a complex process. The runtime proceeds through the deserialization process sequentially, starting at the beginning and working its wasy through to the end. The process gets complicated if an object in the serialized stream refers to another object. If an object references another object, the Formatter queries the ObjectManager to determine whether the referenced object has already been deserialized (a backward reference), or whether it has not yet been deserialized ( a forward reference). If it is a forward reference, the Formatter registers a fixup with the ObjectManager . A fixup  is the process of finalizing an object reference after the referenced object has been deserialized. Once the referenced object is deserialized, ObjectManager completes the reference. 

Limiting Threads in a ThreadPool

The ThreadPool class supports methods for setting the number of minimum and maximum thread in the thread pool. In most circumstances, yhe number of threads is the pool is set at optimum numbers. If you find that your application is being constrained by the threads in th thread pool, you can set the limits yourself. There are two types of situations where you will want to change the thread pool thread limits: thread starvation and startup thread speed. In thread-starvation scenario, your application is using the thread pool but is being hampared because you have two many work items and you are reaching the maximum number of threads in the pool. To set the high watermark of threads for your application, you can simply use ThreadPool.SetMaxThreads. In cases where the startup costs of using the thread pool are expensive, increasing the minimum number of threads can improve performance. The minimum number of threads dictates how many threads are created immediately and set to wait for

Deploying COM-Enabled Assemblies

Although an assembly can be created visible to COM, one should follow below guidelines to ensure that things work as planned: All classes must use a default constructor with no parameters. Any type that is to be exposed must be public. Any member that is to be exposed should be public. Abstract classes will not be able to be consumed. After these criteria are met, the assembly is essentially ready to be exported. There are two mechnisms to do so. One can use VS or a command line utility(TlbExp.exe). First you need to compile the type through Visual Studio's build mechanism or through command line compiler as               csc /t:library ComVisiblePerson.cs Next you need to use Type Library Exporter Utility. This should be done from VS command prompt:               tlbexp ComVisiblePerson.dll /out:ComVisiblePersonlib.tlb Next oyu need to create  resource script (ComVisiblePerson.res) with the following Interface Definition Language (IDL) definition:               IDR_TYPE

Moving a type (i.e. class) to another assembly

In .NET, one often refers to other assemblies that contain specific modules that you can use in your application. Say, you reference a DLL that contains some classes that you will use in your application. Suppose the application is deployed. Now, suppose you want to move one class of the DLL to another assembly. What can you do in this situation with old coding methodoligies? The old methodologies say, Remove the class from the existing DLL. Create another DLL (assembly) using that class. Recompile both the DLLs. From your application, add a reference to the new DLL. Recompile the application. Re-deploy the whole thing. Wouldn't it be nice to leave the deployed application untouched, and make whatever changes are needed in the DLLs? Obviously, that would be nicer. That's where the TypeForwardedTo  attribute comes into the scene. By using this, you can move your necessary classes out to a new assembly. Now, when your application looks for the class in the old DLL, th

Running one process on multiple processors

A thread in a process can migrate from processor to processor, with each migration reloading the processor cache. Under heavy system loads, specifying which processor should run a specific thread can improve performance by reducing the number of times the processor cache is reloaded. The association between a processor and a thread is called the processor affinity. Each processor is represented as a bit. Bit 0 is processor one, bit 1 is processor two, and so forth. If you set a bit to the value 1, the corresponding processor is selected for thread assignment. When you set the  ProcessorAffinity  value to zero, the operating system's scheduling algorithms set the thread's affinity. When the  ProcessorAffinity  value is set to any nonzero value, the value is interpreted as a bitmask that specifies those processors eligible for selection. The following table shows a selection of  ProcessorAffinity  values for an eight-processor system. Bitmask Binary value Eligible

WebSite vs WebApplication

The only similarity between a web site and a web application is that they both access HTML documents using the HTTP protocol over an internet or intranet connection. However, there are some differences which I shall attempt to identify in the following matrix: Web Site Web Application 1 Will usually be available on the internet, but may be restricted to an organisation's intranet. Will usually be restricted to the intranet owned by a particular organisation, but may be available on the internet for employees who travel beyond the reach of that intranet. 2 Can never be implemented as a desktop application. May have exactly the same functionality as a desktop application. It may in fact be a desktop application with a web interface. 3 Can be accessed by anybody. Can be accessed by authorised users only. 4 Can contain nothing but a collection of static pages. Although it is possible to pull the page content from a database such pages are rarely updated after they have been crea

Are cloud storage providers good for primary data storage?

Why not use a cloud storage provider? The most persuasive argument against using cloud storage for primary storage  is application performance. Application performance is highly sensitive to storage response times. The longer it takes for the application's storage to respond to a read or write request, the slower that application performs.  Public cloud storage by definition resides in a location geographically distant from your physical storage when measured in cable distance. Response time for an application is measured in round-trip time (RTT). There are numerous factors that add to that RTT. One is speed of light latency, which there is no getting around today. Another is TCP/IP latency. Then there is a little thing called packet loss that can really gum up response time because of retransmissions. It is easy to see that for the vast amount of SMB(small mid sized business) primary applications, public cloud storage performance will be unacceptable.  When do cloud storage