-1

I've a problem with a multithreading app in C# and I would appreciate some help, since I'm new to multithreading.

This is the scenario: I'll have a mobile app that will do a lot of queries/requests in my database(Mysql), my goal is to make a server side application that handles multiple queries using C# in a Linux machine(mono to the rescue). My company is doing the database side of the application, there's another company making the mobile app. I'll send the data to the cloud and the cloud server will send it to the client.

I'm reading the threading chapters of CLR via C# and C# 4.0 in a nutshell, but until now I have only a little clue of what I can do, I believe that asynchronous methods would work, since it doesn't use a lot of resources but I'm a little confused about how to handle thread concurrency(priority, state).

So here are my questions:

  • What is the best way to solve this problem?
  • Which class from .NET framework suits best for this job?
  • How should I handle the query queue?
  • How can I handle thousands of threads/queries fast enough, so my mobile app user can have the query result in a estimated time of 5 minutes?

Some observations:

I know that the data and time to finish a query will be exponentially equal to the size of the user's data in my database, but I need to handle(few and large data) it as fast as I can.

I'm sending the data to a cloud database(Amazon EC2) and from there i'll send it to the client. I'll not handle this, this will be handled by another company, so my job is to get the queries done quickly and make them avaliable to the cloud database.

I'm aware that to send the information to my client I depend on my IT infrastructure, but the point here is: how I can solve this problem quickly in a way that I'll have only to worry about my application infrastructure.

I cannot put the queries on a big string and throw it on the database, because I need to handle each query result separately before sending the result to the user.

The storage engine is MyISAM, so no transactions are allowed.

John Peter
  • 73
  • 1
  • 1
  • 5
  • It is a little unclear how the mobile app will communicate with the database - could you elaborate? If you build a web api, you would probably get the webserver to handle a lot of the threading issues. Moreover, using a standard web server you get a lot of monitoring and diagnosis tools to boot. – Rune Aug 06 '14 at 20:10

1 Answers1

3

I would create a REST web service, either on top servicestack or WebAPI, to abstract access to your data via a service. Either of these services would be able to handle simultaneous requests from your mobile client, as they are designed to do so. In addition, I would create a class that can mediate access and provide a unit-of-work to your database (ie repository). The connection provider for MySQL should be able to handle simultaneous requests from your web service, so you should not have to worry about threading and request management. If a single instance is not enough, you can add more web servers running the same code and use a load-balancer to distribute the requests to each of your instances, where the service/data code is the same.

Some resources for mono based web-api/servicestack:

http://www.piotrwalat.net/running-asp-net-web-api-services-under-linux-and-os-x/

What is the best way to run ServiceStack on Linux / Mono?

Community
  • 1
  • 1
wbennett
  • 2,545
  • 21
  • 12