SQLDatabase: Read a lot of data at once and process in memory or read the data when I need it?

I'm not sure how to approach this problem. I require a big chunk of data records from the SQL server. This chunk is based on variables, so I don't know before what records I need. I need to do a large series of calculations and each calculation requires one
(or more) records from this chunk of data. Again: I do not know which records are required.
Should I:
A. Load this data into the application memory all at once
This creates a single connection to the DB, loads ALL required data by a query command (and a forward only DataReader) and then doesn't bother the SQL server anymore.
The datafetch seems to be slow, since it's reading hundred of thousands of lines into memory
B. Whenever the calculation needs data, retrieve it from the database
This would open and close a connection to the SQL db multiple times per second.
The initial datafetch is reduced to only a few miliseconds, but creates a massive load on the SQL server during calculation.

Firstly, if you can turn your whole calculation in to an SQL query (or a series of queries or a stored procedure) then do so. Databases are good at this stuff, and you or a DBA may be able to do a lot to improve the query if it's still too slow.
If not:
Use a connection pool. Not doing so is usually crazy, unless you're writing a script that only connects once or twice.
If you're testing this in a development environment with a local DB, beware that there can be a big difference in performance characteristics compared to a production one and don't over-optimize based on what you measure. Network delays in particular could
catch you out. Fetching one row at a time may be fine with a low network latency, and awful with a high one.
Database sizes are usually bigger in production, and go up over time. If you fetch all the data in advance you could get caught out and run out of memory (unless you know more about your data then we do...).
As Pieter B suggests, you're probably better fetching data in batches if you really need a large number of rows. Then you'll neither blow everything else out of your server's memory, nor have a network latency and query overhead on every row. It'll also help
if you want to report progress to the user.
If you're really serious about making it go as fast as possible and not using SQL to do it, then you could try parallelizing your code. Then you can be calculating with
one set of data whilst fetching the next, and if your production DB has multiple cores and disks you can parallelize in the DB, too. You could also look at caching, if that's appropriate (memcached and similar, or directly in your server if you know your data
sizes well enough).

Similar Messages

  • SAP MII 14.0 SP5 Patch 11 - Error has occurred while processing data stream Dynamic Query role is not assigned to the Data Server

    Hello All,
    We are using a two tier architecture.
    Our Corp server calls the refinery server.
    Our CORP MII server uses user id abc_user to connect to the refinery data server.
    The user id abc_user has the SAP_xMII_Dynamic_Query role.
    The data server also has the checkbox for allow dynamic query enabled.
    But we are still getting the following error
    Error has occurred while processing data stream
    Dynamic Query role is not assigned to the Data Server; Use query template
    Once we add the SAP_xMII_Dynamic_Query role to the data server everything works fine. Is this feature by design ?
    Thanks,
    Kiran

    Thanks Anushree !!
    I thought that just adding the role to the user and enabling the dynamic query checkbox on the data server should work.
    But we even needed to add the role to the data server.
    Thanks,
    Kiran

  • How do i keep only the name of a month in a cell in Numbers and not have it auto fill the date and time?

    how do i keep only the name of a month in a cell in Numbers and not have it auto fill the date and time?

    Hi JN and Barry,
    Barry wrote:
    The second case may not be included in the available D&T formats in Numbers 3
    For my region, the Date & Time data formats include month.
    The Date Pop-Up
    This may not be the case for all regions.
    Remember that the month is only the display, and the Full Date & Time is still there. If I change the format to reveal what is behind the curtain:
    Regards,
    Ian.

  • HT1766 I have an iphone 4.I upgraded it to 5.0.1 and so I have lost all the data from my iPhone,but i have a backup in my computer.How do I use the backup file ? i.e How will i get that backup file in my iPhone ?

    I have an iphone 4.I upgraded it to 5.0.1 and so I have lost all the data from my iPhone,but i have a backup in my computer.How do I use the backup file ? i.e How will i get that backup file in my iPhone ?

    Connect phone to computer.
    Select Restore.
    Tell iTunes which of the available backup files to use, let iTunes restore it.
    Also, try reading the User's Guide as it answers questions like this.

  • Why does my iPod touch take a lot of time to update and download apps? I got the one of the fastest wifi

    Why does my iPod touch take a lot of time to update and download apps? I got the one of the fastest wifi

    Try this:
    Close all apps in the Task Bar. Double-click the Home button and hold apps down for a second or two. Tap the minus sign to close app.

  • I added 0AMOUNT in generic data source and in rsa3 i am seeing the data ..b

    i added 0AMOUNT in generic data source and in rsa3 i am seeing the data ..but i am not seeing any data in target table..
    what would be the cause

    Hi,
    I guess you mean the target table in BW, correct?
    First replicate your DSource in BW
    Open your TRules. In tab Transfer structure/Datasource locate your field in the right pane (should be greyed, not blue); move it from to the left (to the transfer structure); reactivate and reload.
    You should now see the field in your PSA table.
    hope this helps...
    Olivier.

  • Since last week my date & time have not worked on my 5c. The date & time are constantly wrong. I've shut down, doesn't work. Set it automatically, doesn't work. I don't get texts or calls when it's sleeping. Any suggestions?

    Since last week my date & time have not worked on my 5c. The date & time are constantly wrong. I've shut down, doesn't work. Set it automatically, doesn't work. I don't get texts or calls when it's sleeping. Any suggestions?

    try a reset.
    Hold the home & power buttons down simultaneously until you see the Apple logo appear.
    Note: no data will be lost.

  • HT1212 i recently upgraded my OS, all my data is backed up on my laptop, to restore the data i need  to enter the password to my phone data backup, which i forgot, is there anyway i could get back?

    i recently upgraded my OS, all my data is backed up on my laptop, to restore the data i need  to enter the password to my phone data backup, which i forgot, is there anyway i could get back?

    No. If there was a way of getting hold of the password, it wouldn't be much of a security system, would it?  The backup is lost if you can't remember.

  • HT201413 suddenly itunes will not open and I get a message that the "Data Execution Prevention" is blocking itunes from opening....why????

    itunes will not open and I get a message that the "Data Execution Prevention (DEP)" feature in Windows is preventing it from opening. (this is after I've been using itunes for years???? If I try to manually deselect itunes from the DEP filter, of course I get a message that itunes cannot operate without the DEP active...another Catch 22 from the evil program designers....

    Go to Control Panel > Add or Remove Programs (Win XP) or Programs and Features (later)
    Remove all of these items in the following order:
    iTunes
    Apple Software Update
    Apple Mobile Device Support (if this won't uninstall move on to the next item)
    Bonjour
    Apple Application Support
    Reboot, download iTunes, then reinstall, either using an account with administrative rights, or right-clicking the downloaded installer and selecting Run as Administrator.
    The uninstall and reinstall process will preserve your iTunes library and settings, but ideally you would back up the library and your other important personal documents and data on a regular basis. See this user tip for a suggested technique.
    Please note:
    Some users may need to follow all the steps in whichever of the following support documents applies to their system. These include some additional manual file and folder deletions not mentioned above.
    HT1925: Removing and Reinstalling iTunes for Windows XP
    HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
    tt2

  • Hierarchies Job Failing  The job process could not communicate with the dat

    Hi Experts,
    We have a group of hierarchies that run as a separate job on the DS schedules. The problem is this when we schedule the job to run during the production loads it fails but when we run immediately after it fails it runs completely fine. So it basically means that if i run it manually it runs but when its scheduled to run with the production job it fails. Now the interesting thing is If i schedule the job to run anytime after or before the production jobs are done. It works fine.
    The error i get is
    The job process could not communicate with the data flow <XXXXXX> process. For details, see previously logged
                                                               error <50406>.
    Now this XXXXX DF has only Horizontal Flatenning and it does not run as separate process because if i have it has separate process it fails with an EOF . So i removed the run as separate process and changes the DF to use in memory .
    Any Suggestion on this problem...

    Thanks Mike.. I was hoping its a memory issue but the thing i don't understand is when the job is scheduled to run with the production job it fails. when i manually run the job during the production job it runs, this kinda baffles me.
    DS 3.2 (Verison 12.2.0.0)
    OS: GNU/LINUX
    DF Cache Setting :- In Memory
    processor       : 0
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 26
    model name      : Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
    stepping        : 4
    cpu MHz         : 2933.437
    cache size      : 12288 KB
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 11
    wp              : yes
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc ida nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm
    bogomips        : 5866.87
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 40 bits physical, 48 bits virtual
    power management: [8]
    processor       : 1
    vendor_id       : GenuineIntel
    cpu family      : 6
    model           : 26
    model name      : Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
    stepping        : 4
    cpu MHz         : 2933.437
    cache size      : 12288 KB
    fpu             : yes
    fpu_exception   : yes
    cpuid level     : 11
    wp              : yes
    flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc ida nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm
    bogomips        : 5866.87
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 40 bits physical, 48 bits virtual
    power management: [8]
    Thanks for your help

  • EZ Vinyl Converter problem transferring to iTunes - window appears  "mixmeister programme has stopped working and will shut down". Then the data is lost, and I have to try to record/transfer again.  I have now tried many times.

    EZ Vinyl Converter problem transferring to iTunes - window appears  "mixmeister programme has stopped working and will shut down". Then the data is lost, and I have to try to record/transfer again.  I have now tried many times.
    The deck is ION TTUSB05XL   Laptop   Asus V550C with Windows 8.
    Strangely I did manage to successfully transfer two tracks to iTunes, but all further attempts have failed.
    JJR

    EZ Vinyl Converter problem transferring to iTunes - window appears  "mixmeister programme has stopped working and will shut down". Then the data is lost, and I have to try to record/transfer again.  I have now tried many times.
    The deck is ION TTUSB05XL   Laptop   Asus V550C with Windows 8.
    Strangely I did manage to successfully transfer two tracks to iTunes, but all further attempts have failed.
    JJR

  • My iphone 4s siri is not working, it just worked for a while and stopped. I've checked the data plan and it is intact, i even switched my sim to a friends phone and his siri worked but mine refused even with a wireless network. pls help.

    My iphone 4s siri is not working, it just worked for a while and stopped. I've checked the data plan and it is intact, i even switched my sim to a friends phone and his siri worked but mine refused even with a wireless network. pls help.

    Troubleshooting Siri
    http://support.apple.com/kb/TS4079

  • I have a numbers spreadsheet for tracking company data.  I want to copy the format of the spreadsheet (rows, columns,and formulas) but have all of the data fields be blank for the new year.  How do I do that?

    I have a numbers spreadsheet for tracking company data.  I want to copy the format of the spreadsheet (rows, columns,and formulas) but have all of the data fields be blank for the new year.  How do I do that?

    click and hold on one cell, then drag to select the range, then release, then type the delete key.  Only inlude cells in the range you do not want to keey the contents of the cell.  You can remove one-off cells by holding the command key and clicking cells to add or remove as needed.
    You can download the Numbers users guide here:
    http://support.apple.com/manuals/#productivitysoftware

  • Hi as iam changing the ical message allert date to daybefore automatically it is changing to on the date please help me, hi as iam changing the ical message allert date to daybefore automatically it is changing to on the date please help me

    hi,
    As iam changing the ical message allert date to "daybefore" automatically it is changing to "on the date"   
    please help me,

    You could simplify the decode(... into to_char(sysdate + 1,'d')
    select sysdate + level input_date,
           TRIM(TO_CHAR(SYSDATE + level,'DAY')) the_day,
           DECODE(TRIM(TO_CHAR(SYSDATE + level,'DAY')),
                  'SATURDAY',1,
                  'SUNDAY',2,
                  'MONDAY',3,
                  'TUESDAY',4,
                  'WEDNESDAY',5,
                  'THURSDAY',6,
                  'FRIDAY',7
                 ) daynumber,
           to_char(sysdate + level + 1,'d') alternative
      from dual
    INPUT_DATE
    THE_DAY
    DAYNUMBER
    ALTERNATIVE
    10/14/2013
    MONDAY
    3
    3
    10/15/2013
    TUESDAY
    4
    4
    10/16/2013
    WEDNESDAY
    5
    5
    10/17/2013
    THURSDAY
    6
    6
    10/18/2013
    FRIDAY
    7
    7
    10/19/2013
    SATURDAY
    1
    1
    10/20/2013
    SUNDAY
    2
    2
    10/21/2013
    MONDAY
    3
    3
    10/22/2013
    TUESDAY
    4
    4
    10/23/2013
    WEDNESDAY
    5
    5
    10/24/2013
    THURSDAY
    6
    6
    10/25/2013
    FRIDAY
    7
    7
    10/26/2013
    SATURDAY
    1
    1
    10/27/2013
    SUNDAY
    2
    2
    10/28/2013
    MONDAY
    3
    3
    Regards
    Etbin

Maybe you are looking for

  • Using Multiple AD domains with ACS

    Hi, Is it possible to use multiple domains for authentication with ACS? I need to use AAA to authenticate remote users into a centralised location but the users will be from different domains and I was hoping to use a single applicance to cater for a

  • USB Medical Device not recognized by iMac or Windows through Parallels 7 Virtual Machine

    I have a USB Medical device which initially i was using through a Windows based Laptop, I want to connect it to my iMac to use it through Parallels on Windows 7. The device is not recognized by my iMac therefore it is not recognized by the virtual ma

  • Wireless and Ethernet Network Do Not Work Other Than SpeedTest

    I have been having major problems with my Mac's Internet.  Whenever I connect to my Wireless or Ethernet Connection, the signal start out strong and dies down to almost nothing (around .4 kbps) immediatly.  I have been having this problem for a coupl

  • Counting tokens in a GUI

    hey all im a first time poster and a first year IT student so sorry if this is old hat but i need a hand. Im using a standard Tokenizer...in a GUI . I have it that the program prints each token (word or whatever) on a seperate line to each other in t

  • Size of avm1movie in as3

    Hi, I'm developing a new website in as3, and would simply like to load the adobe media gallery (as2) swf for one section. I'm new to flash, but have managed to get the as2 content to load. The trouble is that the as2 movie expands to the size I've de