Slashdot Mirror


Dumping Lots of Data to Disk in Realtime?

AmiChris asks: "At work I need something that can dump sequential entries for several hundred thousand instruments in realtime. It also needs to be able to retrieve data for a single instrument relatively quickly. A standard relational database won't cut it. It has to keep up with 2000+ updates per second, mostly on a subset of a few hundred instruments active at a given time. I've got some ideas of how I would build such a beast, based on flat files and a system of caching entries in memory. I would like to know if: someone has already built something like this; and if not, would someone want to use it if I build it? I'm not sure what other applications there might be. I could see recording massive amounts of network traffic or scientific data with such a library. I'm guessing someone out there has done something like this before. I'm currently working with C++ on Windows. "

23 of 127 comments (clear)

  1. 2-stage approach by eagl · · Score: 5, Informative

    Have you considered a 2-stage approach? Stuff it to disk, and process/index it separately? A fast stream of data would let it all get recorded without loss, and then you could use whatever resources are necessary to index and search without impacting the data dump.

    Cost... Are you going to go for local storage or NAS? Need SCSI and RAID or a less expensive hardware setup? Do you think gigabit ethernet will be sufficient for the transfer from the data dump hardware to the processing/indexing/search machines?

    Sounds like you might want to run a test case using commodity hardware first.

  2. Suuuure. by Seumas · · Score: 4, Funny

    Yeah, like it isn't obvious that this guy works for the government's TIA program and is looking for ways to maintain all of the data culled from the thousands of audio and video sensors they have planted around.

    Suuuure.

  3. Wonderware InSQL by Dios · · Score: 4, Informative


    Check out wonderware InSQL. We update roughly 50k points every 30 seconds without loading the server much at all. Pretty nice product, also has some custom extensions to SQL built in for querying the data (eg cyclic, resolution, delta storage, etc etc).

    http://www.wonderware.com/

    Of course, you'll need your data to come from an OPC/Suitelink/other supported protocol, but should work nicely for you.

    - Joshua

    1. Re:Wonderware InSQL by btlzu2 · · Score: 2, Interesting

      How does archiving work? What is the performance of querying on a large table? (Hundreds of millions of rows) Can you hook into the database with any language/package you desire or proprietary tools only?

      Do you actually charge a license fee PER point?

      We had a need for a smaller SCADA system in our company and Wonderware could not answer these questions (except for the fee per point, which they actually charge PER POINT). This department is going with a different product.

      Sorry, but be very cautious of Wonderware.

      --
      Zed's dead baby. Zed's dead.
    2. Re:Wonderware InSQL by btlzu2 · · Score: 2, Informative

      We stopped at the investigation phase. They couldn't answer simple questions and were going to charge us if we needed to add more points. Unacceptable.

      SCADA is very versatile and powerful. Are you feeding data in mostly from local or remote RTU's?

      You do understand that SCADA is a general term which describes a type of system, right? A SCADA system could be designed (and has been) :) that is not versatile and powerful. Sorry to be nitpicky, but I'm just trying to understand what you mean.

      Anyway, we work with a much larger SCADA system vendor, which actually has the SCADA market share for our industry. Wonderware would never come close to providing the functionality we'd need in our industry and we do not want to be tied to a Microsoft platform.

      Wonderware was a candidate for a smaller sub-system, but we've decided to go with another system that's working out very well--is more open for development purposes and is generally better designed. I wasn't on the smaller project, but I was on the big system project and continue to maintain and develop for it.

      SCADA is a fun area to work in for geeks--loads of administration, development, design opportunities in various techologies including, but not limited to, LANs, WANs, telecommunications, backend/frontend development, database maintenance, etc.

      --
      Zed's dead baby. Zed's dead.
    3. Re:Wonderware InSQL by Dios · · Score: 2, Informative


      InSQL works as an OLE Processes for SQL Server. You can use pretty much any tool (ODBC/ADO/excel/DAO/whatever) to query the database. Yes I realize I mixed libraries/methods/applications in the tool list, but just trying to get across a basic idea.

      Yes, per point licensing, I believe we licensed for 60k points, not sure on the cost. This is pretty typical in the SCADA world I believe.

      Sample query I'd use to get all data for a specific rtu
      select * from live where tagname like 'StationName%'

      Two tables use typically work with, live and history. Live between the latest values, history for historical queries.

      As for query times, very respectable. I believe we have about 50k points right now, updated/stored every 30 seconds (Actually, its delta storage, so some discrete points who don't change every 30 seconds would be stored only on change...). So how many rows is that?

      1440 minutes per day * 2 samples per minute * 50000 points * 180 days (approx history we have online) = 25,920,000,000 rows.

      We have asp pages people query the data from, we limit 30 second resolution data to only 2 days at a time (to help prevent loading down the machines) but a query for any point will typically return in a few seconds.

      We are pretty satisfied with the product, may not fit your needs, but its been good for us.

  4. Don't roll your own by btlzu2 · · Score: 3, Informative

    Unless you really want to do a LOT of work. This sounds very much like a SCADA system. There are vendors of such systems. Most of the realtime databases are designed to stay in a large, proprietary, RAM database which is occasionally dumped to disk for backup purposes.

    In order to process so many points realtime, it usually will have to be in RAM for performance reasons.

    --
    Zed's dead baby. Zed's dead.
  5. Cluster it by canuck57 · · Score: 3, Insightful

    I know your working with windows but when I read this I said yes.

    I'm guessing someone out there has done something like this before.

    Google has a cluster of machines far larger than you need but their approach was a Linux cluster. Plus, for the amount of writes going on your going to want not to have any burdens on the system that are not needed.

  6. A commercial RDMS can cut it by jbplou · · Score: 4, Informative

    You can definitely use Oracle to write out 2000 updates per second if your hardware is up to it and your db skills are good.

    1. Re:A commercial RDMS can cut it by gvc · · Score: 4, Interesting

      "Can [the storage backend] handle 2000 random seeks per second?"

      The short answer is "no."

      A 10,000 RPM disk has a period of 6 mSec. That's 3 mSec latency on average for random access (not counting seek time or the fact that read-modify-write will take at least 3 times this long: read, wait one full rotation, write).

      So one disk can do, as a generous upper bound, 333 random accesses per second. I'll spare you the details of the Poisson distribution, but if you managed to spread these updates randomly over a disk farm, you'd need about 2000/333*e = 16 independent spindles.

      The trick to high throughput is harnessing, and creating, non-randomness. You can do a much better job of this with a purpose-built solution.

  7. Yes, this sort of thing has been built before by Andy_R · · Score: 2, Informative

    I have a system that can record 32 streams of data 44,100 times per second. It's called a recording studio, and I make music with it.

    If your data streams are continuous, and can be represented as audio data, then you are pretty much dealing with a solved problem, and your other problem of selecting from large number of possible 'instruments' is solved by an audio patchbay.

    If this isn't feasible, then a number of solutions might be appropriate (spreading the load over a number of machines/huge ram caches/buffering/looking at the problem and thinking of a less intensive sampling strategy/etc.) but without more information on the sort of data you are collecting, and exactly how quickly you need to access it, it's very hard to be specific.

    --
    A pizza of radius z and thickness a has a volume of pi z z a
  8. horizontal scaling is good... by anon+mouse-cow-aard · · Score: 2, Interesting

    Sure, optimize single node performance first, but keep in mind that horizontal scaling is something to look for. Put N machines behind a load balancer, ingest gets scattered among 'n' machines, queries go to all simultaneously. Redundant Array of Inexpensive Databases :-)

    Linux Virtual Server in front of several instances of your windows box will do, with some proxying stuff for queries. Probably cheaper than spending months trying to tweak single node to get to your scaling target, and will scale trivially much farther out.

  9. Re:Have you tried a relational database? by LuckyStarr · · Score: 2, Interesting

    I agree. In fact SQLite performs quite well on a reasonable sized machine. 3000+ SQL updates on an indexed table should be no problem.

    --
    Meme of the day: I browse "Disable Sigs: Checked". So should you.
  10. The Solution by cwraig · · Score: 2, Funny

    the solution to your problem comes in the form of a little known software application from a vender called Microsoft.
    The program is called Microsoft Access 97
    :P

  11. Ramdisk database by Glonoinha · · Score: 4, Informative

    Here's a thought - just use a hard-RAM based database.
    Either make a big ramdisk and put your database out there (see my Journal from a few months back, ramdisk throughput is pretty damn fast from the local machine, given certain constraints, and random access writing is hella fast), or use a database that runs entirely in memory (think Derby, aka Cloudscape that comes with WebSphere Application Developer.)

    When you got your data, save it out to the hard drive.

    Granted it helps to have a box with a ton of memory in it, but they are out there now, almost affordable. If you are collecting more than 4G of data in one session, well YMMV - but 4G is a LOT of data, perhaps consider your approach.

    --
    Glonoinha the MebiByte Slayer
    1. Re:Ramdisk database by Glonoinha · · Score: 2, Insightful

      You will find that my imagination and abilities are only limited by my budget. Well that and, as I am finding, the Sarbanes / Oxley mandates that recently came down from the Productivity Prevention Team, quite effective in keeping me from actually getting any work done.

      I don't really care what it pays if it has anything to do with real-time systems (guidance or delivery systems a plus), if the R&D budget has enough wiggle room for better hardware (toys) than I have at home, if you promise that I will be able to participate in the production roll-out and be allowed to make the production environment succeed, and esp if there are a few challenges that are categorized "can't be done."

      Apollo 13 didn't get home because a bunch of mediocre guys sat around filling out paperwork requesting permission and setting up a committee to discuss business impact - Apollo 13 got home because a bunch of crack-junkie hardcore engineers decided that failure wasn't an option.

      So the stuff you do at work - is it hard? :)

      --
      Glonoinha the MebiByte Slayer
  12. Did something like this some years ago by isj · · Score: 2, Insightful
    My current company did something like this back in 2001 with real-time rating performance, which conceptually is much like what you want to do: receive a lot of items and store them in a database, real-time. But you did not mention some of the more important details about problem:
    • How much processing has to be done per item?
    • How long can you delay comitting them to a database?
    • Do the clients wait for an answer? Can you cheat and respond immediately?
    • How many simultaneous clients must you support? 1? 5? 100?
    • What is the hardware budget?

    2.000 items/sec means that you must do bulk updates. You cannot flush to disk 2.000 times per second. So you program will have to store the items temporarily in a buffer, which gets flushed by a secondary thread when a timer expires or when the buffer gets full. use a two-buffer approach so you can stil receive while committing to the database.

    Depending on you application it may be beneficial to keep a cache of the most recent items for all instruments.

    You also have to consider the disk setup. If you have to store all the items then any multi-disk setup will do. If you actually only store a few items per instrument and update them, then raid-5 will kill you because it performs poorly with tiny scattered updates.

    Do you have to backup the items? How will you you handle backups while your program is running? This affects your choice of flat-file or database implementation.

  13. Yup... by joto · · Score: 2, Informative
    Someone has done this before. It's called a data acquisition system. The basic design for one is even sketched out in one of Grady Booch's books (before he became one of the three amigos).

    The design of a data acquisition systems will of course differ, depending on how much data it records per sensor, how many sensors there are, how often to record the data, and if the data is to be available for online or offline processing.

    In most of the "hard" cases, you will use a pipelined architecture, where data is received on one or more realtime boxes, and buffered for an appropriate (short) period. A second stage occurs when data is collected from these buffers, and buffered/reordered/processed to make writing the desired format to a file or DBMS easier. The last stage, is, of course, to write it. You might use zero or more computers at each stage, with a fast dedicated network in-between. You might even decide to split up some of the stages even further. Depending on how much you care about your data, you may also add redundancy. And make sure it's fault-tolerant, it's generally better to loose some data, as long as it's tagged as missing, than to loose it all. To check this in real-time you can also add data-monitoring anywhere it makes sense for your system.

    In the simper cases, you simply remove things not needed, such as a soundcard instead of dedicated realtime-boxes, redundancy, monitoring, dedicated network, etc...

    Some commercial off-the-shelf systems will surely do this. But the more advanced systems, you still build yourself, either from scratch, or by reusing code you find in other similar projects (I'm sure there are some scientific code available from people interested in medical science, biology, astrophysics, geophysics, meteorology, etc...).

    Most of the "heavy" systems will not run on Windows, or even Intel, due to limitations of that platform for fast I/O. This has obviously changed a lot recently, so it's no longer the stupid choice it was, but don't expect too many projects of this kind to have noticed, as they probably have existed much longer.

  14. Have you considered memory-mapped files? by Teancum · · Score: 3, Interesting

    I did some work on a DVD-Video authoring system that had some incredible file system requirments (obviously, when involving video data and the typical 4 GB data load for a single DVD disc).

    The standard file API architechture just didn't hold up, so we (the development team I was working with) had to rewrite some of the file management routines ourselves and work directly with the memory mapped architechture directly. This does give you some other advantages beyond speed as well, as once you establish the file link and set it in a memory address range you can treat the data in the file as if it were RAM within your program, having fun with pointers and everything else you can imagine. Copying data to the file is simply a matter of a memory move operation, or copying from one pointer to another.

    The thing to remember is that Windows (this is undocumented) won't allow you to open a memory-mapped file that is larger than 1 GB, and under FAT32 file systems (Windows 95/98/ME/and some low-end XP systems) the total of all memory mapped files on the entire operating system must be below 1 GB (this requirement really sucks the breath out of some applications).

    Remember that if you are putting pointers into the file directly, that it works better if the pointers are relative offsets rather than direct memory pointers, even though direct memory pointers are in theory possible during a single session run.

  15. Specialized Hardware by mschaef · · Score: 2, Informative

    This may be gross overkill, but there's specialized hardware specifically designed for sustained high-throughput disk storage. A company called Conduant makes specialized disk controllers that use on board microcontrollers to drive arrays of disks. When I last saw them demoed, they could sustain writes of 100MB/sec using direct card to card transfers across the PCI bus. They can configure a data acquisition card to directly store information into a shared buffer on the disk controller across the PCI bus. The disk controller then picks the data up and drives it across ten IDE channels. That was a few years ago, these days it looks like they can sustain 200MB/sec with a controller, and up to 600MB/sec and 6TB of capacity with custom box mounted in a rack.

    I'm not so sure what their story is regarding reading or querying. My guess is you lose a lot of bandwidth, but not all. Anyway, it might be worth checking out.

    http://www.conduant.com/products/overview.html

    Another thing is that modern computers cam have lots innate capacity themselves. My hunch is that you could do a lot with a couple modern disks on seperate SATA channels and several GB of RAM. Maybe this is only a software problem...

  16. Kdb+ by RussHart · · Score: 3, Informative

    Kdb+ by KX Systems (http://www.kx.com/ is by far and away the best thing for this. Its main use is to store tick data from financial markets, and is excellent at this (if expensive).

    From how you descibed your needs, this would probably bit the bill..

  17. NetCDF or HDF5 by Salis · · Score: 2, Informative

    NetCDF and HDF5 are optimized binary file formats for storing incredibly large amounts of data and quickly retrieving it.

    I'm more familiar with NetCDF (because I use it) so let me tell you some of the things it can do. (HDF5 can also do these things, I'm sure).

    With NetCDF, you can store +2 gigabyte files on a 32 bit machine (it supports Large File support). I've saved 12 gigabyte files with no problems. It supports both sequential and direct access, meaning you can read and write either starting from the beginning of the file or at any point in the middle of the file.

    The format is array-based. You define dimensions of arrays and variables consisting of zero, one, or more dimensions. You can also define attributes that are used as metadata, information describing the data inside your variables.

    You can read or write slices of your data, including strides and hyperslabs. This allows you to read/write only the data you're interested in and makes disk access much faster.

    It's also easy to use with good APIs. They have APIs for C, Fortran95, C++, MATLAB, Python, Perl, Java, and Ruby.

    Take a look at it. It might be what you're looking for.

    -Howard Salis

    --
    Favorite /. tagline: "On the eighth day, God created FORTRAN." And it was good.
  18. HP-IB and ISAM by Decker-Mage · · Score: 3, Informative
    This was what the Hewlett Packard Interface Bus (HP-IB) was invented for and your instruments may already be equipped for it. As for what to do with the data stream from the instruments, you stuff it into an ISAM database. Why anyone would even think of using an RDBMS for this is beyond me. ISAM (Indexed Sequential Access Method) has been around forever, exists to take tons of sequential data and store it to the media of choice. From your description, retrieval is only going to be based on a few criteria anyway (instrument, time), so those indices are perfect in this instance.

    On the coding end, there are numerous (hell, hundreds) of commercial, F/OSS, and books on ISAM libraries for you to use for the actual storage and retrieval. It may even be included in your existing libraries given how old the technique is now. I was doing this back in the '80s for the US Navy using a 24 bit, very slow, mini-computer, so any normal box should be able to handle it today!

    We use these techniques in electronic instrument monitoring, logistical systems, systems engineering, you get the idea. You may want to mosey over to the HP developer web site to see if there is a drop in solution, as I imagine there is (sorry, haven't looked).

    I hope this helps.

    --
    "[I]t is a wise man who admits the limits of his knowledge or skill, and that pretending either causes harm." --Terry Go