Why is asynchronous database access so much slower?

Hi, I have an AIR app that loads and parses a data file
(approx 170 MB) and stores the parsed data in a database using the
built-in SQLite functionality. I have two implementations: one
synchronous, another asynchronous, both use transactions. The
synchronous one takes approx 5 minutes to complete. The
asynchronous takes approx 2.5 hours. The choice thus seems to be
between having an unresponsive program for 5 minutes, or having to
wait too long.
Did anyone else observer this significant difference? Is
there a 'known' reason for it? Is there anything that could
potentially be done to reduce the run time of the asynchronous
approach?

Thanks for posting your code; that helps a lot. I think
you'll find it instructive to watch CPU usage during the two demos.
Here's what's going on.
In the synchronous code, you are keeping the application busy
100% of the time because as soon as each insert is complete you
immediately schedule the next one. That's efficient although, as
you note, it makes the application unresponsive for too long a
period of time.
In the asynchronous code you are also waiting for each insert
to complete before scheduling the next one. The work done behind
the scenes for each insert is therefore greatly expanded:
1) An event is posted from the UI thread to a background
worker thread, scheduling the insert
2) The background thread wakes up
3) The insert executes on the background thread
4) The background thread posts an event containing the
results back to the UI thread
5) The UI thread eventually processes that event, delivering
it to your code
As you can see, there's a tremendous amount of overhead to
this. This is not really the way the async API is intended to be
used. Instead, try one of the following strategies:
A) Don't wait for each statement to complete before running
the next one. They'll queue up and run in order, but because the
background thread can process many at once, it runs much faster.
B) Chunk your synchronous inserts, e.g., run 100 inserts
every 100 msec or so. (You'll have to measure to find optimal
numbers.)
Hope this helps.

Similar Messages

  • Database is too much Slow

    Hi All,
    My database is running on window Xp oracle 10g and it is very slow
    the os is having 1gb ram and sga is very slow this may cause the problem
    here i am attaching the spfile so please let me know that which parameter is to be incraese so that we can incraese the performance of the system,
    Thanks in advace,
    Nitesh
    *.background_dump_dest='C:\oracle\product\10.1.0\admin\orcl1\bdump'
    *.compatible='10.1.0.2.0'
    *.control_files='C:\oracle\product\10.1.0\oradata\orcl1\control01.ctl',
    'C:\oracle\product\10.1.0\oradata\orcl1\control02.ctl','C:\oracle\product\10.1.0\oradata\orcl1\control03.ctl'
    *.core_dump_dest='C:\oracle\product\10.1.0\admin\orcl1\cdump'
    *.db_block_size=8192
    *.db_cache_size=25165824
    *.db_domain=''
    *.db_file_multiblock_read_count=16
    *.db_name='orcl1'
    *.db_recovery_file_dest='C:\oracle\product\10.1.0\flash_recovery_area'
    *.db_recovery_file_dest_size=2147483648
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=orcl1XDB)'
    *.java_pool_size=50331648
    *.job_queue_processes=10
    *.large_pool_size=8388608
    *.open_cursors=300
    *.pga_aggregate_target=25165824
    *.processes=150
    *.remote_login_passwordfile='EXCLUSIVE'
    *.shared_pool_size=83886080
    *.sort_area_size=65536
    *.undo_management='AUTO'
    *.undo_tablespace='UNDOTBS1'
    *.user_dump_dest='C:\oracle\product\10.1.0\admin\orcl1\udump'
    waiting for your early reply..........

    Out of 1GB RAM only 160 is allocated to shared pool, buffer cache, large pool and java pool. This is too low.
    Enable SGA_TARGET_SIZE and let Oracle decide the optimum value for different pools according to the workload. If performance is satisfactory you can disable SGA_TARGET_SIZE and the optimum values are stored in the spfile or otherwise you can continue with automatic memory management.

  • Why is iwork 09 apps SOOOOO MUCH slower to open then MS word on a PC???????

    Hi,
    I would like to know if other people have noticed this, or it's just on my MBP, that it takes way longer to open a pages document than opening MS word on a 1 yr old computer running VISTA??? ***?
    Word opens instantly and on my Mac it takes like 10-12 seconds!!!

    There are several factors.
    It is not coded identically obviously so it is hard to determine exactly what is being done in the first few seconds of start up. Also to what degree Apple has optimised its performance by writing key functions in machine code.
    Another big factor would be the Hard Drive speed in your computer. The small HDs in laptops are markedly slower than desktop models for example. Also how much real and virtual memory is available.
    I'm not going to defend Pages just for the sake of it but there are lots of ways making software appear to respond more quickly by partially loading stuff and then making you wait later on. Microsoft for all you know may have preloaded key Microsoft Software on launching Vista on the PC, so it may already have been in memory. You could check in Vista by monitoring what is happening when you launch Word in a process monitor.
    Do you have the same number of fonts on both machines?
    Also Pages maybe checking other things such as media in iPhoto, iTunes etc.
    I suspect it may also have to decompress the resources in its application bundle.
    Whatever the reason you should let Apple know:
    +Menu > Pages > Provide Pages Feedback+
    Peter

  • Database Access delays-how to improve upon that?

    Hi friends,
    I have this simple class,which takes in query and returns the results.I don't know why the database access is so slow,and if i try to add my driver load statements into the constructor the java class starts throwing "null pointer exception"(Java Class code given below)..I don't know much about connection pool,can u just have a look at this simple class,and tell me if there's anything on which i can improve upon and where to add the(*.close() statements).The same query runs instantly if i make a php program.Urgent help needed...please help me guys.
    public class getResultSet{  private Connection con = null;  private Statement st = null;  private String dsn = "jdbc    b2j:net:xxx";  private String uname = "xxx";  private String pwd = "xxx";  private String query = "";  ResultSet results;   public void ResultS()throws Exception{      try{          Class.forName("com.ibm.db2.jcc.DB2Driver");          con = DriverManager.getConnection(dsn, uname, pwd);          st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,                                   ResultSet.CONCUR_READ_ONLY);         }      catch (SQLException e) {          e.printStackTrace();          }     }     public ResultSet getResults(String query){            results = null;            try{               results = st.executeQuery(query);               }               catch(SQLException sqle){                 sqle.printStackTrace();               }            return results;     }   }

    Some comments on the code
    public class getResultSet{ // Class names should start with a capital letter and be nouns
    private Connection con = null;
    private Statement st = null; // Statements are transient and should probably not be a member variable
    private String dsn = "jdbc    b2j:net:xxx";  // dsn, user, pass should be final
    private String uname = "xxx"; 
    private String pwd = "xxx"; 
    private String query = "";  // Seems you're not using this
    ResultSet results;   // This really shouldn't be declared here
    public void ResultS()throws Exception{ // Method should start with a lower-case letter and be a verb/* The client code is supposed to call this, then the other method?
    Very fragile. I'm guessing NullPointerExceptions occur if ResultS
    is not called first. Have the other method call this one as necessary.
    try{        
    Class.forName("com.ibm.db2.jcc.DB2Driver");
    con = DriverManager.getConnection(dsn, uname,
    uname, pwd);
    st =
    st =
    =
    con.createStatementResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ultSet.CONCUR_READ_ONLY);
    catch (SQLException e) {  
    e.printStackTrace();
    public ResultSet getResults(String query){      
    results = null;
    try{          
    results = st.executeQuery(query);
    catch(SQLException sqle){   
    sqle.printStackTrace();
    return results; // It's a bad idea to return ResultSets as that leaves resources open
    } // Where's the cleanup? You're leaving ResultSet, Statement, Connection open
    >It is probably slow because opening connections takes a long time. You may or may not need a connection pool depending on your app. Perhaps you can just open a connection at the beginning and leave it open until your app finishes. That should reduce the overhead and still be very simple.

  • Database access... what is the best approach

    in a nutshell...
    i have an applet that needs to access three data bases... currently i have it written and completed and working but the lag time on the database access is really slow so i am questioning my approach to the problem...
    as a buisness rule we wanted to create classes to access the data through accessor mehtods from applications and appletts therfore standardizing our field name conventions, our methods and so on and so on...
    so when the applett runs it creates an object for each class that access the database... when the user enters a valid "parcel number" the parcel is passed to the first class and the record is retrieved for database "A" and then it is passed to the next class and the supporting records are retrieved for data base "B" and it repeats the same concept for database "C".. so now i have the applet running and accessing the data through accessor methods through those objects...
    each class makes the conection to the data base.. issues the sql, stores the results and closes the connection
    i'll admit i am somewhat new to the java envirnoment so any help on concepts and approach would be most appreciated and useful
    does this approach seem reasonable or am i letting my 15 years of procedural thinking get the best of me...
    what would be the most effiecent way of doing this?
    how much of a performance gain would i see if i threaded each one out on it's own thread and how would i do that?
    the end product is going to be a county taxation system using browser technology as an inquiry system for public and general use and an application environment for inhouse data entry and use
    creating seperate classes for each of the data basses seems ideal for what we want to do but maybe it is counterproductive considering the lag times.
    i am using JDBC against an HP3000 image DataBase

    With the information given that is the only possible approach.
    You could provide a middle layer which would then handle some of the interactions for you. For instance by keeping a connection pool.
    Additionally if your databases are not actually distributed (and the same vendor) then you could do most of the work in a stored procedure. You could also do this if some of the data is relatively static and by using a server side replication process.

  • Slow database access across network

    I have a postgresql database setup on a server machine and have written a java program in netbeans that accesses it. The problem i have is that running the jar created by netbeans from any other machine on the network has really slow database access but running the program from netbeans itself is fine. Running the jar on the server machine is also fine.
    Anyoner got any idea as to why this could be?
    Tom

    I don't know if this will help, I'm just wading into writing my own java apps to hit a SQL 2K db. We purchased a SQL2k/JSP driven backend on which we extended their OM to meet our needs. It was build as an extranet product but ran very poorly across the 'Net.
    The biggest annoyance was not the actual transaction time of the app but the time it took from the end user to click a button and the start of the transaction.
    After much testing I determined it was the JSP.
    So what we have done to alieviate the issue is to have multiple regional Tomcats that 'throw' their transactions to a central colocation where the SQL servers sit (so the tomcats do the JSP managment in a sense locally to the end user) . For big clients we actually place a linux/tomcat box at the edge of their firewall. For whatever reason, I'm far too busy to determine the how now that I get the responses I need, this has completely eradicated the annoying pause between user interaction and the actual transaction to the DB server. Extended testing showed the SQL server running in the sub half second range to process a command but the tomcat rendering could take up to 2 to 5 seconds in worst case for no discernable reason. Moving the tomcat frontends to the network segment where the clients we solved it.
    Of course I'm digging into swing now too and it has some slowness that the Eclipse zealots say SWT fixes but I haven't the depth or experience to properly judge the camps arguments yet.
    hth...

  • Firefox much slower connecting to all web sites than Internet Explorer. Why?

    Over the last few weeks, Firefox has become much slower connecting to virtually all web sites that I frequent than does Internet Explorer. Nothing has changed on my computer other than occasional downloads of Firefox "improvements".

    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox and the plugin-container from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process and the updater process.
    See:
    *https://support.mozilla.org/kb/Server+not+found
    *https://support.mozilla.org/kb/Firewalls
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Why does this forum perform much slower than form forum in metalink?

    I feel strongly that this forum performs much slower than the form forum in metalink where there are even more active and more issues created there.
    I don't know why Oracle creates two form forum, which one is faster and another one is slower.
    What is the difference b/w them besides here is jsp pages and over there is plsql pages?

    Oracle certainly allows you to have users that do not have roles. Or users that don't have any system privileges. Or users that don't have any object privileges.
    If you want the query to return a row for every row in DBA_USERS, you would need to outer join all the other tables to DBA_USERS.
    Justin

  • Why can I not access My iPhone on my Air - they have the same cloud account - same iTunes - logged onto the same wifi network... and connected via USB - difficult much?!its killing me ahhh my screen smashed and i want access to my iPhone on my macbook

    Why can I not access My iPhone on my Air - they have the same cloud account - same iTunes - logged onto the same wifi network... and connected via USB - difficult much?!its killing me ahhh my screen smashed and i want access to my iPhone on my macbook..
    why is it sooo hard still --- can anyone inform me on this miracle app please
    thank you
    sincerely
    Theigalaxy

    find my iphone is something one needs to activate on the phone itself using the same appelID is nowhere near enough
    if it is then one can track, play a sound and remote whipe it from
    www.icloud.com
    if your screen is smashed and you think you can use find my iphone to get any data from your phone you are sadly mistaken

  • Why can't i access my itunes anymore? whenever i click on it, it makes my laptop freeze/slow down to the point where not even ctrl alt delete works properly and i have to turn the laptop off and then back on to get anything done.

    why can't i access my itunes anymore? whenever i click on it, it makes my laptop freeze/slow down to the point where not even ctrl alt delete works properly and i have to turn the laptop off and then back on to get anything done. it has been this way for the last 2/3 days now and i have uninstalled and reinstalled it but it doesnt work

    Hello there, bobbiefromIRL.
    The following Knowledge Base article goes over some great steps for troubleshooting your issue:
    iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues
    http://support.apple.com/kb/ts1717
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • Why is Mac OS X 10.7 so much slower than Snow Leopard? It isnt smooth, applications are slow and most dont respond, and dowloads take hours, minutes.

    Why is Mac OS X 10.7 so much slower than Snow Leopard? It isnt smooth, applications are slow and most dont respond, and dowloads take hours, not minutes.

    Something is seriously wrong with your installation or you are critically low on RAM, like below 2 GB.
    How much RAM is in your machine?
    Have you tried a Recovery?

  • Preview takes forever to open, much slower than on my old MacBook. It has been like this since I bought the computer last January. Why is Lion so much slower?

    Preview takes forever to open, much slower than on my old MacBook running Snow Leopard. It has been like this since I bought the computer last January. Any ideas?

    Take it to an Apple Store for testing. If you don't get immediate satisfaction, exchange it for another one, which you can do at no cost, no questions asked, within 14 days of delivery.

  • Why is my iPhone4 so much slower than my iPad2 on my home wireless network?

    I have installed a new Linksys 3200 wireless router.  And, I find that my iPhone4 is MUCH slower on the wi-fi network than my iPad2.  I expected it to me slower, but not this much!  Here are the speedtest results:
    iPhone4 - Ping at 399 ms, Download speed at .73 Mbps, Upload speed at 1.00 Mbps
    iPad2 - Ping at 84 ms, Download at 5.63 Mbps, Upload at .91 Mbps
    My cable modem is supposed to be rated at 5/1 (Download/Upload), so it seems that the iPad is maximizing the use.
    I've tried a complete shutdown and restart (modem first, then router, then computer).  And, it seems a little faster, but not much.
    Is there something wrong with the iPhone?  I don't remember it being so slow before...and it seems faster on my office network!
    Suggestions, please.
    Robert

    P.S.  It also seems to lose the connection from my iPhone4 pretty easily.  I have to go back to settings and reset the wireless network.  (Don't have to on the iPad).
    Robert

  • I have Windows 2000, DSL access, and just updated to Firefox 7 which seems to run much slower in many ways: any thoughts?

    Firefox starts as quickly as before, but switching between tabs or closing tabs often takes forever. Also when I drag to highlight a long page and copy, the scrolling speed is much much slower than before. To highlight a long passage I have to drag just the beginning, hold that with the Shift key and use the arrow keys to highlight the whole passage within any reasonable time. Closing Firefox is usually as quick as before, but once in a while it gets constipated and takes 30+ seconds to close -- though I suspect this might have something to do with some open tabs. (By "close" I'm referring to when it leaves the screen, not later when it is dropped from memory.) I average 3 or 4 open tabs with brief periods of 8 or 9 open tabs.

    Please try this: '''Tools''' (or '''Alt''' + '''T''') > '''Options''' > '''Advanced''' > '''General'''. Under '''Browsing''' deselect '''Use autoscrolling''', '''Use smooth scrolling''', '''Use hardware acceleration...''' if any are selected.
    You may also want to boomark these for occassional reference:
    [https://support.mozilla.com/en-US/kb/Options%20window All about Tools > Options]
    [https://support.mozilla.com/en-US/kb/Keyboard%20shortcuts Keyboard Shortcuts]
    [http://kb.mozillazine.org/About:config_entries about:config Entries]
    [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode]
    [http://kb.mozillazine.org/Problematic_extensions Problematic Extensions/Add-ons]
    [https://addons.mozilla.org/en-US/firefox/performance/ Slow Performing Extensions/Add-ons]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]

  • Why is the new iOS 6 so slow?

    Why is the my iPad 3 running so slow now I have updated to iOS 6. Also unable to access the app shop

    Agree the new ios6 is much slower. I found this post by doing a search to find out if it was only me. I've done off &amp; on &amp; a soft reset. Neither helped. Everything seems to load much slower &amp; hangs.
    Maybe the new apps aren't optimized yet. However, I had one of my worst experiences with the Apple App Store. One would think they'd know how to optimize their own site &amp; app.
    I just hope it's not a bloat issue because the "upgrades" are not worth the performance trade offs to me.
    Also, the iMaps are definitely not ready for prime time. I tried getting directions between two locations that were very mainstream and the app said it couldn't provide directions. I'll take Google without turn by turn, thank you. At least let us have a choice and let the best app win.

Maybe you are looking for

  • How to go from HDV050i 16x9 video to a PAL SD 4x3  DVD?

    Hi. I have the following situation. I have shot HDV footage in 50i mode. This material is of coarse in 16x9. I need to make it into a PAL SD 4x3 DVD. I don't mind if the sides of the image is cut off. I use the latest version of Final Cut Studio. Thi

  • ClassCastException When we use JSP with Normal Bean in WebLogic 5.1

              Hai Everybody...           We have an application where JSP files are using the Normal Java beans(Nothing           but a Java Class).Here all jave beans are in a folder ..\myserver\classfiles\           and the jsp files are in ..\myserver

  • To Change color of search area

    When you click on content administration you get browse and search tabs..when you click on search you get a search area .iam not able to change the color of the search area background...any pointers Regards Radhika Kuthiala

  • Timeline Best Practices?

    I am fairly new to flash and I have been trying to make a product demo. Basically I want some text to fade in and then some pictures to show up one by one and then disappear and then some new text fades in etc. This is to talk about a product and sho

  • Need Help Please!   RE: iMac Apps Deleted

    HI, I am trying to help a family member who has an iMac 2011? Running Snowleopard.  He deleted several items from a Finder Window, such as "PREVIEW".  He dragged it into the trash and emptied the trash.   (Please don't ask me why-I don't know!)    Do