455,122 Members | 1,237 Online
Need help? Post your question and get tips & solutions from a community of 455,122 IT Pros & Developers. It's quick & easy.

# Expert Query on timing, threads, networking plz.... :S

 P: n/a Two quick queries: 1. I have programmed a little network performance monitor. It monitors a set of remote hosts over a network. It gets the CPU statistics and all gets collected at one of the remote hosts (say primary remote host, holding procValues[n][4], 4 CPU floating numbers per n remote hosts). Now, I want to transfer this data set (double procValues[n][4]) over a TCP or UDP network connection to a local host for graphing and storing in a database tool. I've read Beej's Networking Guide http://www.ecst.csuchico.edu/~beej/guide/net/ and going to follow his code. However I don't know how am going to send a double[n][4] over the network efficiently without hogging the network. Is the most efficient way just converting double[n][4] into a string? Am using a sleep(1) function to set the frequency of 1 second to read the cpu statistics. If a sending function takes more than the frequency of "cpu statistic collecting" then am going to get lots of missed out data... no wait it wouldn't be perfectly synchronized to the exact second, it will be lagged behind. Maybe thread the network transfer so that the frequency of "cpu collecting" remains precisely every second? What are your views? 2. How does one create/use threads in C, AND C++? Do threads differ in usage in C and C++? Jul 23 '05 #1
5 Replies

 P: n/a >>However I don't know how am going to send a double[n][4] over thenetwork efficiently without hogging the network. Is the most efficientway just converting double[n][4] into a string? First send the value of n, then send each double value in a loop.Receiving side, n will determine the no of double values to recieve.Maybe thread the network transfer so that the frequencyof "cpu collecting" remains precisely every second? You may consider a list of data sharing between both thread and access should be syncronized between them. data collecting thread will collect data and add this to rear of list and other thread will take the as much as data availabel in list and will copy it and send it to network.2. How does one create/use threads in C, AND C++? Do threads differ in usage in C and C++? If you are on windows , use beginthreadex(). Search "multithreading C++" on google. Also consider the synchronization issues, you may use mutex , critical section etc depending upon situations. Jul 23 '05 #2

 P: n/a >>then send each double value in a loop Sorry, why need loop? just send it as one buffer, they are arrays, i forgot that. Jul 23 '05 #3

 P: n/a What? Just pass the 2-dimensional array? How? Jul 23 '05 #4

 P: n/a KevinGPO wrote: Two quick queries: (...) Now, I want to transfer this data set (double procValues[n][4]) over a TCP or UDP network connection to a local host for graphing and storing in a database tool. I've read Beej's Networking Guide http://www.ecst.csuchico.edu/~beej/guide/net/ and going to follow his code. However I don't know how am going to send a double[n][4] over the network efficiently without hogging the network. Is the most efficient way just converting double[n][4] into a string? If you plan on using send and recv (as is suggested by the link), you have no option besides converting the 2D array into a string (for send) and reading the character stream (from recv) to retrieve the double values. NB: Neither send nor recv belong to the standard libraries of C and C++. (...) 2. How does one create/use threads in C, AND C++? Do threads differ in usage in C and C++? The core languages (and their libraries) do not offer any support for threads (yet?!). You need to use POSIX extensions to C for this purpose. Try comp.unix.programmer. - Anand Jul 26 '05 #5

 P: n/a How about using message queuing model. I always find it good when there is the case of data loss because of different speeds of producer and consumer. You can create a queue and then dump the data into it. Another task/thread can read data from it and process it at its own will. So you will not lose data but the graph which you will be displaying will be a bit older than the actual stats. Jul 26 '05 #6

### This discussion thread is closed

Replies have been disabled for this discussion.