Wednesday, 3 March 2010

SharePoint 2010 Preliminary System Requirements

I probably will work on SharePoint for a while.
Microsoft announced preliminary system requirements for SharePoint server 2010. Obviously it goes for some big enterprise with enough budget.
  1. SharePoint Server 2010 will be 64-bit only.
  2. SharePoint Server 2010 will require 64-bit Windows Server 2008 or 64-bit Windows Server 2008 R2.
  3. SharePoint Server 2010 will require 64-bit SQL Server 2008 or 64-bit SQL Server 2005.

Wednesday, 10 February 2010

Threads allocated in ActiveMQ and options

I found a very nice post about threads allocated in ActiveMQ consumer, broker and producer. http://fusesource.com/wiki/display/ProdInfo/Understanding+the+Threads+Allocated+in+ActiveMQ
In the testing I did, Connection is really created in a new thread. Session part I am not sure. Do not know how to test it. OnMessage() always comes to same thread (different with connection thread). It is wired

Two wire protocol supported in ActiveMQ

Default wire protocol supported by ActiveMQ is Java OpenWire transport. OpenWire is used to marshal objects to byte arrays and back. http://activemq.apache.org/openwire.html
Another one is Stomp. The Stomp project is the Streaming Text Orientated Messaging Protocol site (or the Protocol Briefly Known as TTMP and Represented by the symbol :ttmp).
Stomp provides an interoperable wire format so that any of the available Stomp Clients can communicate with any Stomp Message Broker to provide easy and widespread messaging interop among languages, platforms and brokers.
I think wire protocol is the way ActiveMQ pack messages to byte arrays. OpenWire and Stomp are two different ways here. As ActiveMQ website says "OpenWire is designed for maximum performance and features; its the protocol used inside ActiveMQ. If you want a simpler protocol to work with to get started with a cross language client then tryStomp which is designed for ease-of-implementation so its easy to support many clients." So it is your choice.

Monday, 1 February 2010

Why UI application hangs and top possible reasons

These days I am investigating freezing UI application problem. It is very painful. No clues.
I tried reading logs of UI application, checking socket connection status, memory and CPU usage. But it does not help. Everything seems fine.
I tried to add logs when entering and leaving locks in UI application. It seems fine. Entering and leaving match.
I also tried Windows debugging tool and ANTS performance profiler. They are not really helpful since freezing does not happen all the time. And Windows debugging tool is kind of difficult to use. You need spend some time to learn how to use it. It is not straightforward telling you what is wrong with your codes.

The problem was finally solved 'by accident'. Somebody changed something and magically UI stopps hangging any more.
Take a look at change history, we found out hanging is caused by cross thread problem of UI application. UI thread creates a new UI object. The handler on the new UI object starts to doing something. The later change is to put these codes in a safe invoke scope. It looks like as followings.
UIObject b = new UIObject(); //For example a button
if ( b.InvokeRequired )
{
// fall into here if new thread is needed
}
else
{
//fall into here if no new thread is needed
}
So top issues I will focus on if unfortunately I have to investigate this problem again
1) CPU and memory usage. They are always the first suspect and easy to check.
2) Threads number of this application. Easy to check.
3) UI update should be covered in safe Invoke/BeginInvoke/EndInvoke scope. Just like the above example.
4) lock problems.

Tuesday, 19 January 2010

Lifetime of static variable

From MSDN http://msdn.microsoft.com/en-us/library/aa645766%28VS.71%29.aspx

A field declared with the static modifier is called a static variable. A static variable comes into existence before execution of the static constructor (Section 10.11) for its containing type, and ceases to exist when the associated application domain ceases to exist.

The initial value of a static variable is the default value (Section 5.2) of the variable's type.

For purposes of definite assignment checking, a static variable is considered initially assigned.

Monday, 18 January 2010

InstanceContextMode and ConcurrencyMode

There are three InstanceContextMode in WCF.
  • PerCall: a new InstanceContext object is created and recycled succeeding each call.
  • PerSession: A new InstanceContext object is created per session and instance is not sharable by multiple sessions.
  • Single: A single instance is created and used for all incoming calls.
There are three ConcurrencyMode supported by WCF.
  • Single: The service instance is single threaded and does not accept reentrance calls. If a new message comes when another message is being processed, this message has to wait there until the first one is finished.
  • Multiple: The service is multi-threaded. It is fast. No waiting. But developer has to make sure the code is thread-safe.
  • Reentrance: The service is single threaded and can accept reentrant calls. It implies that the service processes only one message at a given time. To ensure thread safety, WCF locks the InstanceContext processing a message so that no other messages can be processed. In case of Reentrant mode, the InstanceContext is unlocked just before the service makes an outgoing call thereby allowing the subsequent call to get the lock next time it comes in to the service.
There are many factors we should think about when choosing service behavior.
  • Constructor of service. Probably InstanceConxt. Single should be used if there are lots of stuff to load and initialize. InstanceContext.PerSession should be used if there are states to maintain for one client. No thing to maintain for different calls, different clients, InstanceContext.PerCall should be used.
  • ConcurrencyMode does not matter if InstanceContextMode.PerCall is adopted. New available thread will be used if new call comes.
  • InstanceContext.PerCall and InstanceContext.PerSession mean same thing if there is no session maintained for this service
  • ConcurrencyMode.Reentrant does not mean multiple thread. It is single thread in most cases except there is outgoing service call.
  • Take care of thread-saftety if InstanceContextMode.Single and ConcurrencyMode.Multiple are considered to use. It will be faster and it will also be tricky.
We could put some logs to know when the object is initialized and which thread is used in the constructor. Just for confirmation.

Monday, 4 January 2010

OptimisticConcurrencyException-When it is triggered?

It could be triggered in two cases:
1)The entity property is defined in the conceptual layer with an attribute of ConcurrencyMode="fixed"(A property of Entity Framework, Not SQL Server).When this attribute is used, Object Services checks for changes in the database before saving changes to the database. Any conflicting changes will cause an OptimisticConcurrencyException.
By default, however, Object Services saves object changes to the database without checking for concurrency.

2)An OptimisticConcurrencyException can also occur when you define an Entity Data Model that uses stored procedures to make updates to the data source. In this case, the exception is raised when the stored procedure that is used to perform updates reports that zero rows were updated.