Click here to Skip to main content
15,923,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a class library that uses a web refrence of a web service I made. The web service has a property, to use a Database or not to use a database. If I use a database it retains the information. But I am worried that because the web service constantly insert and delete information, using the Database will become the bottle neck of the program.

So my goal now is to have my information be retained through OS refreshing of the service. Any idea how to do this?

Also I am an CS student who is going to their sophomore year, and currently an intern just for the summer. Learned C# and used Visual studio for the first time during this intern. I love it! Also the guy that is supervising said he will be busy and if I need help, I could use this website!

[UPDATE]
In my web service I have
public class Service1 : System.Web.Services.WebService
   {
       private SqlConnection connection;
       private List<ListData> ListOfMessages;
       public Service1()
       {
           if (Properties.Settings.Default.UseDatabase)
           {
               try
               {
                   connection = new SqlConnection(Properties.Settings.Default.DbConnectionStr);
                   connection.Open();
               }
               catch (Exception ex)
               {
                   Console.WriteLine(ex);
               }
               Dispose(false);
           }
           else
           {
               ListOfMessages = new List<ListData>();
               Dispose(false);
           }
       }
}
Posted
Updated 8-Jul-11 10:24am
v2

What sort of perfromance / scale / use do you reasonably expect you are actually going to need? You might be worried about something that isn't ever going to be an issue.

Don't spend time solving a problem that doesn't need to be solved.

Databases are supposed to be optimised to support lots of transactions per second. That's what they are supposed to be good at.

You aren't going to be able to implement a database replacement that's better than a database if what you really need is a database.

If what you need is a database, then use a database.

If it becomes a bottleneck, then configure your database better or replace it with a faster database (or throw hardware at it).

If you don't need a database, then what data are you actually trying to persist? To persist data, it essentially needs to be written to persistent storage (and maybe cached on the way for faster write/read) -- but that's what a database does.

A pure read/write of a file may actually be slower than using a database.

There are in-memory databases if you don't actually care about persisting across a power failure.
 
Share this answer
 
Comments
Member 8015046 8-Jul-11 16:51pm    
I guess he wants me to use in-memory database. Thanks! I am going to look that up.
TRK3 8-Jul-11 16:57pm    
What I think you should do, is go ahead and write your class / web-service and use it and see if there is a performance problem or not.

It might be just fine. In which case, do nothing. If there is a performance problem, then use some tools to find out where the bottleneck really is.

If, and only if, it turns out to be the database, then analyse what the database is doing and figure out a better way to configure the database (or use an in-memory database, or turn on disk caching, or change your index, or...)

But don't spend time on solving something that you just think is a problem until you actually know it's a problem.
Member 8015046 8-Jul-11 17:11pm    
Well when he is not busy anymore, I would like to present him both solutions. So I have looked up things. I believe using DBF.NET is what I am trying to go for.
[no name] 9-Jul-11 1:51am    
Excellent. My 5.
I think that a few improvement can be done to your code:

  • Don't eat exceptions in a constructor. Your service object would not be "usable" if something goes wrong.
  • What is the Dispose call inside the constructor?
    Dispose is not intended to be called from the constructor but from the caller when he does not need the object anymore.
  • If you want to be ready to support different data store options, uses an interface to that repository and implement concrete class for each possible case (SQL Database, in-memory database...)


In order to select which option to choose, we should have an idea of:

  • The amont off data returned by the service (record count and data size)
  • The total amont of storage
  • Does the returned data vary by user, by time or seldom changes?
  • How many request you expect per second
  • ...


That being said, in most case a database is the only option if the data needed to be permanent or if the data is huge.

If you have a lot of data to return each time (say 1000 item or more per request) and each item is small and you don't need to index each item separatly, then it might make some sence to group some data in one SQL record. For example, one SQL record might be 1 minute of data if you record 10 samples per second.

Finally, I think that a lot can be done on the server side if you need more performance like having a web farm or dedicated hosting instead of shared hosting.
 
Share this answer
 
v2
Comments
[no name] 9-Jul-11 1:53am    
Good Call.My 5.
Member 8015046 9-Jul-11 16:20pm    
He told me it is going to be millions of time. And the data I am not sure.

Like a small example would be like one list has a list name and a List of strings. But maybe like a linked list because we are just adding things to the end and reading+deleting from the beginning. Like taking out of the queue. But I know there is going to be many list and many messages.

He said if the program doesnt have memory leaks the web service will be on all the time.If it does it will have to be reseted or something. And the data going back and fourth or just strings.

Also how many request per second. All I know it needs to be fast
The best thing to do is to define your service around an interface:

public interface IRepository
{
    void AppendData(string name, string value, DateTime timeStamp);
    string[] GetData(string name, DateTime from, DateTime to);
}


Then you will have concreate implementations:
public SqlRepository : IRepository
{
    void AppendData(string name, string value, DateTime timeStamp)
    {
        // SQL implementation
    }

    string[] GetData(string name, DateTime from, DateTime to)
    {
        // SQL implementation
    }
}

// Similar for MemoryRepository.


Then it will be easy to select or compare each possibilities. You could also implement other possibilities like SqlWithCacheRepository where you keep mostly used data in memory.
 
Share this answer
 
Comments
Member 8015046 9-Jul-11 18:46pm    
This seems very interesting. I am going to look this up more. Do some speed test on it. Thanks for the idea!
TRK3 11-Jul-11 10:21am    
Good concrete suggestion. Probably exactly what OP needs to show him how to implement it now and change the data store later when he finds he needs to -- which is what I was saying. My 5.
I just saw the following article on online MSDN magazine. I haven't read it yet but I though that might interest you.

Master Large Data Streams with Microsoft StreamInsight

http://msdn.microsoft.com/en-gb/magazine/hh205648.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900