Apart from what Keith mentions, there are a few things you can take into consideration.
Proper design for a particular purpose depends on leveraging your knowledge about the data model, and the operations that will be performed on the data.
There is nothing that prevents multiple threads executing the same static methods in parallel, and you can almost think of non-static methods as static methods with a hidden parameter: “this”. That’s how it works in c++ for instance – virtual methods are a bit more complicated as they require a level of indirection through a class specific table of methods, but the analogy is still useful.
Usually some key data merits preloading into the application, while most of the data does not. Access to, and manipulation of, preloaded data requires locking – as your web service will be usually be multithreaded – separate threads servicing parallel requests. Management those data items are often done using the
singleton[
^] pattern, where a single static property or method provides access to an instance of the management class ensuring one, and only one instance, of the management class. The instantiation process of the instance of the management class must be protected in a manner that prevents multiple threads from instantiating multiple instances of the management class.
When designing such a system I prefer to investigate the possibility of leveraging
ReaderWriterLockSlim[
^] in non-recursive mode. A reader/writer lock allows multiple concurrent threads to read data at the same time, while locking out all others for write operations.
The way you organize your data, choose locking mechanisms, and so on – is eventually what is going to determine the level of performance you will get out of your design.
If you keep all your data in a database, reloading it for each request – using a separate connection to the database – you have something that mimics the behavior of a regular web application. This will usually be easier to design, but don’t be surprised if somebody creates a similar application that outperforms your application by a 1000 to 1. By understanding your data model, and leveraging that knowledge in your design to create queries against the database using information kept in memory to simplify the queries, you will hopefully be able to do much to improve the performance of your application.
Regards
Espen Harlinn