Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Adventures in Async

Adventures in Async

Scheduled Pinned Locked Moved The Lounge
htmldatabasecomgraphicsalgorithms
51 Posts 21 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jorgen Andersson

    Never bothered with Async programming before since I never needed it. But now I'm having to take care of a weekly delivery of an 80 GB (eighty gigabyte) large XML-file. The parsing and saving 10 million records to 30 different tables in a database takes more than an hour and there's no simple optimization left to do. But I only use one kernel in the processor, so let's go parallell, it'll be fun learning. Right? Easiest part is bulk copying to the database in parallel. Easy enough but it only shaves five minutes from the total time. This is not where the biggest bottleneck is. The biggest bottleneck is the actual parsing of the XML. I don't want to rework the whole application into using locks and thread-safe collections so I decide to split the work vertically instead. Add a task for every collection of data. Also easy enough, now the processor is working close to 100%, but it takes twice as long. :wtf: Apparently the creation of tasks has more overhead than the parsing of the data itself. :laugh: No shortcuts for me today. Back to the drawing board.

    Wrong is evil and must be defeated. - Jeff Ello

    Richard DeemingR Offline
    Richard DeemingR Offline
    Richard Deeming
    wrote on last edited by
    #6

    Are you loading the entire file into an XmlDocument or XDocument? It might be better to stream the file using the XmlReader class. It's a lot more work for you, but it should improve the performance. How to perform streaming transform of large XML documents (C#) | Microsoft Docs[^]


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

    J 1 Reply Last reply
    0
    • J Jorgen Andersson

      Kornfeld Eliyahu Peter wrote:

      a place where data transfer is done in 80GB XML files it seems to be feasible

      Well, that's governments for you. :rolleyes:

      Wrong is evil and must be defeated. - Jeff Ello

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #7

      No way! I work with gov and they just bright and smooth... cream-dela-cream... (today is the 5th week I'm waiting for a version update - still there are personnel to sign it)

      "The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      J 1 Reply Last reply
      0
      • J Jorgen Andersson

        OriginalGriff wrote:

        Oh yes, as soon as your thread count exceeds the core count, you are going to get some slowdown.

        Didn't even do that. :) I'm fully aware of where I wen't wrong. I posted it for netizens of the lounge to have a laugh on my behalf. In this case the specific problem is that the piece of work is smaller than the cost of creating tasks. And my error in the bigger picture is that one cannot simply convert a task running in sync to one running in async. It has to be purpose built.

        Wrong is evil and must be defeated. - Jeff Ello

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #8

        Jörgen Andersson wrote:

        netizens of the lounge to have a laugh on my behalf.

        We wouldn't do that! :laugh:

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        K 2 Replies Last reply
        0
        • Richard DeemingR Richard Deeming

          Are you loading the entire file into an XmlDocument or XDocument? It might be better to stream the file using the XmlReader class. It's a lot more work for you, but it should improve the performance. How to perform streaming transform of large XML documents (C#) | Microsoft Docs[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #9

          I'm using an XMLReader to chop up the filestream into an XDocument for every record. Using an XMLReader all the way became to much work, handling null nodes and such stuff.

          Wrong is evil and must be defeated. - Jeff Ello

          realJSOPR 1 Reply Last reply
          0
          • J Jorgen Andersson

            Never bothered with Async programming before since I never needed it. But now I'm having to take care of a weekly delivery of an 80 GB (eighty gigabyte) large XML-file. The parsing and saving 10 million records to 30 different tables in a database takes more than an hour and there's no simple optimization left to do. But I only use one kernel in the processor, so let's go parallell, it'll be fun learning. Right? Easiest part is bulk copying to the database in parallel. Easy enough but it only shaves five minutes from the total time. This is not where the biggest bottleneck is. The biggest bottleneck is the actual parsing of the XML. I don't want to rework the whole application into using locks and thread-safe collections so I decide to split the work vertically instead. Add a task for every collection of data. Also easy enough, now the processor is working close to 100%, but it takes twice as long. :wtf: Apparently the creation of tasks has more overhead than the parsing of the data itself. :laugh: No shortcuts for me today. Back to the drawing board.

            Wrong is evil and must be defeated. - Jeff Ello

            Greg UtasG Offline
            Greg UtasG Offline
            Greg Utas
            wrote on last edited by
            #10

            If the parsing can be partitioned into n subproblems, where n is the number of cores, then I would consider creating n daemons and locking each one into its own core. If any of them block, offloading the blocking operations to thread pools might help. Partitioning the problem will help to reduce semaphore contention and cache collisions. But I haven't had to populate a large database this way, so I could be full of shite. :-D

            Robust Services Core | Software Techniques for Lemmings | Articles

            <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
            <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

            J 1 Reply Last reply
            0
            • Greg UtasG Greg Utas

              If the parsing can be partitioned into n subproblems, where n is the number of cores, then I would consider creating n daemons and locking each one into its own core. If any of them block, offloading the blocking operations to thread pools might help. Partitioning the problem will help to reduce semaphore contention and cache collisions. But I haven't had to populate a large database this way, so I could be full of shite. :-D

              Robust Services Core | Software Techniques for Lemmings | Articles

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #11

              This is exactly what I didn't want to have to learn. :laugh: At least all proper databases already handle parallel execution properly.

              Wrong is evil and must be defeated. - Jeff Ello

              1 Reply Last reply
              0
              • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                No way! I work with gov and they just bright and smooth... cream-dela-cream... (today is the 5th week I'm waiting for a version update - still there are personnel to sign it)

                "The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012

                J Offline
                J Offline
                Jorgen Andersson
                wrote on last edited by
                #12

                In my case I actually understand them, we're not the only customer on this data, so for them it's just easier to upload a weekly XML file to an ftp-server. And it's not even my own government in this case. I don't understand Danish, and Danes take offence if I speak English to them. (Quite rightly so I might add :) ) So if I want support I need to employ Johnny.

                Wrong is evil and must be defeated. - Jeff Ello

                1 Reply Last reply
                0
                • J Jorgen Andersson

                  Never bothered with Async programming before since I never needed it. But now I'm having to take care of a weekly delivery of an 80 GB (eighty gigabyte) large XML-file. The parsing and saving 10 million records to 30 different tables in a database takes more than an hour and there's no simple optimization left to do. But I only use one kernel in the processor, so let's go parallell, it'll be fun learning. Right? Easiest part is bulk copying to the database in parallel. Easy enough but it only shaves five minutes from the total time. This is not where the biggest bottleneck is. The biggest bottleneck is the actual parsing of the XML. I don't want to rework the whole application into using locks and thread-safe collections so I decide to split the work vertically instead. Add a task for every collection of data. Also easy enough, now the processor is working close to 100%, but it takes twice as long. :wtf: Apparently the creation of tasks has more overhead than the parsing of the data itself. :laugh: No shortcuts for me today. Back to the drawing board.

                  Wrong is evil and must be defeated. - Jeff Ello

                  G Offline
                  G Offline
                  Garth J Lancaster
                  wrote on last edited by
                  #13

                  yup - learn't the hard way, 1st identify where the program uses it's resources

                  1 Reply Last reply
                  0
                  • J Jorgen Andersson

                    I'm using an XMLReader to chop up the filestream into an XDocument for every record. Using an XMLReader all the way became to much work, handling null nodes and such stuff.

                    Wrong is evil and must be defeated. - Jeff Ello

                    realJSOPR Offline
                    realJSOPR Offline
                    realJSOP
                    wrote on last edited by
                    #14

                    I wrote a command line app that imports a NESSUS security scan XML data file - the largest I've seen to date is about 8gb. We import the data into a SQL server database. It's not multi-threaded at all that I recall. I do remember that the file was too big for XDoument to work. I feel your pain.

                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                    -----
                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                    -----
                    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                    1 Reply Last reply
                    0
                    • J Jorgen Andersson

                      Never bothered with Async programming before since I never needed it. But now I'm having to take care of a weekly delivery of an 80 GB (eighty gigabyte) large XML-file. The parsing and saving 10 million records to 30 different tables in a database takes more than an hour and there's no simple optimization left to do. But I only use one kernel in the processor, so let's go parallell, it'll be fun learning. Right? Easiest part is bulk copying to the database in parallel. Easy enough but it only shaves five minutes from the total time. This is not where the biggest bottleneck is. The biggest bottleneck is the actual parsing of the XML. I don't want to rework the whole application into using locks and thread-safe collections so I decide to split the work vertically instead. Add a task for every collection of data. Also easy enough, now the processor is working close to 100%, but it takes twice as long. :wtf: Apparently the creation of tasks has more overhead than the parsing of the data itself. :laugh: No shortcuts for me today. Back to the drawing board.

                      Wrong is evil and must be defeated. - Jeff Ello

                      R Offline
                      R Offline
                      Ron Anders
                      wrote on last edited by
                      #15

                      More proof that some people have real problems. So stop complaining people, you could be Jörgen today.

                      J J 2 Replies Last reply
                      0
                      • J Jorgen Andersson

                        Never bothered with Async programming before since I never needed it. But now I'm having to take care of a weekly delivery of an 80 GB (eighty gigabyte) large XML-file. The parsing and saving 10 million records to 30 different tables in a database takes more than an hour and there's no simple optimization left to do. But I only use one kernel in the processor, so let's go parallell, it'll be fun learning. Right? Easiest part is bulk copying to the database in parallel. Easy enough but it only shaves five minutes from the total time. This is not where the biggest bottleneck is. The biggest bottleneck is the actual parsing of the XML. I don't want to rework the whole application into using locks and thread-safe collections so I decide to split the work vertically instead. Add a task for every collection of data. Also easy enough, now the processor is working close to 100%, but it takes twice as long. :wtf: Apparently the creation of tasks has more overhead than the parsing of the data itself. :laugh: No shortcuts for me today. Back to the drawing board.

                        Wrong is evil and must be defeated. - Jeff Ello

                        S Offline
                        S Offline
                        Stuart Dootson
                        wrote on last edited by
                        #16

                        I was going to say - size of the work done in each task is key... But the underlying technology can also have an effect, by reducing the cost of task creation. If you're using a work queue on top of a thread pool, you're not creating a thread for each task, you're pushing/popping tasks on and off a queue. I created a [little tool to detect duplicate files](https://github.com/studoot/duplicate-finder) using that sort of parallelism. It contains two main areas of parallelism: 1. The [file search library](https://docs.rs/ignore/0.4.16/ignore/) that I use adds a new task for each directory it sees. Each task processes just the files that are immediate children of the directory the task was created for. 2. The detection of duplicates is split so that each task hashes a group of files that have the same size. This is performed using a [data parallelism library](https://docs.rs/rayon/1.3.1/rayon/), which makes parallelising things very easy. The amount of speedup I get isn't anywhere near the number of processor cores in use (I get a factor of just over two speedup on an eight core machine), but I think that the amount of IO being done serialises the processing to a certain degree. Benchmarking [ripgrep](https://blog.burntsushi.net/ripgrep/), another tool that uses similar parallelism, shows that running with 8 threads (on 8 logical/4 physical cores) is just over 3x faster than using 1.

                        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                        1 Reply Last reply
                        0
                        • J Jorgen Andersson

                          Never bothered with Async programming before since I never needed it. But now I'm having to take care of a weekly delivery of an 80 GB (eighty gigabyte) large XML-file. The parsing and saving 10 million records to 30 different tables in a database takes more than an hour and there's no simple optimization left to do. But I only use one kernel in the processor, so let's go parallell, it'll be fun learning. Right? Easiest part is bulk copying to the database in parallel. Easy enough but it only shaves five minutes from the total time. This is not where the biggest bottleneck is. The biggest bottleneck is the actual parsing of the XML. I don't want to rework the whole application into using locks and thread-safe collections so I decide to split the work vertically instead. Add a task for every collection of data. Also easy enough, now the processor is working close to 100%, but it takes twice as long. :wtf: Apparently the creation of tasks has more overhead than the parsing of the data itself. :laugh: No shortcuts for me today. Back to the drawing board.

                          Wrong is evil and must be defeated. - Jeff Ello

                          abmvA Offline
                          abmvA Offline
                          abmv
                          wrote on last edited by
                          #17

                          why are u even parsing xml files and that too 80gb !!! and then saving it to the database !!! .. u could try to use the sql server bulk import tools to do this and avoid programming such stuff all together...

                          Caveat Emptor. "Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long

                          We are in the beginning of a mass extinction. - Greta Thunberg

                          J 1 Reply Last reply
                          0
                          • J Jorgen Andersson

                            Never bothered with Async programming before since I never needed it. But now I'm having to take care of a weekly delivery of an 80 GB (eighty gigabyte) large XML-file. The parsing and saving 10 million records to 30 different tables in a database takes more than an hour and there's no simple optimization left to do. But I only use one kernel in the processor, so let's go parallell, it'll be fun learning. Right? Easiest part is bulk copying to the database in parallel. Easy enough but it only shaves five minutes from the total time. This is not where the biggest bottleneck is. The biggest bottleneck is the actual parsing of the XML. I don't want to rework the whole application into using locks and thread-safe collections so I decide to split the work vertically instead. Add a task for every collection of data. Also easy enough, now the processor is working close to 100%, but it takes twice as long. :wtf: Apparently the creation of tasks has more overhead than the parsing of the data itself. :laugh: No shortcuts for me today. Back to the drawing board.

                            Wrong is evil and must be defeated. - Jeff Ello

                            J Offline
                            J Offline
                            Jeremy Falcon
                            wrote on last edited by
                            #18

                            Welcome to the cool club though. Ladies can't resist an async coder. #science

                            Jeremy Falcon

                            J D 2 Replies Last reply
                            0
                            • R Ron Anders

                              More proof that some people have real problems. So stop complaining people, you could be Jörgen today.

                              J Offline
                              J Offline
                              Jeremy Falcon
                              wrote on last edited by
                              #19

                              Ron Anders wrote:

                              So stop complaining people, you could be Jörgen today.

                              ...and have no toilet paper.

                              Jeremy Falcon

                              1 Reply Last reply
                              0
                              • abmvA abmv

                                why are u even parsing xml files and that too 80gb !!! and then saving it to the database !!! .. u could try to use the sql server bulk import tools to do this and avoid programming such stuff all together...

                                Caveat Emptor. "Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long

                                J Offline
                                J Offline
                                Jorgen Andersson
                                wrote on last edited by
                                #20

                                Because I want to have the data extracted into normalized tables.

                                Wrong is evil and must be defeated. - Jeff Ello

                                abmvA 1 Reply Last reply
                                0
                                • J Jeremy Falcon

                                  Welcome to the cool club though. Ladies can't resist an async coder. #science

                                  Jeremy Falcon

                                  J Offline
                                  J Offline
                                  Jorgen Andersson
                                  wrote on last edited by
                                  #21

                                  That's seriously the best answer today. :-D

                                  Wrong is evil and must be defeated. - Jeff Ello

                                  J 1 Reply Last reply
                                  0
                                  • J Jorgen Andersson

                                    That's seriously the best answer today. :-D

                                    Wrong is evil and must be defeated. - Jeff Ello

                                    J Offline
                                    J Offline
                                    Jeremy Falcon
                                    wrote on last edited by
                                    #22

                                    :-D

                                    Jeremy Falcon

                                    1 Reply Last reply
                                    0
                                    • R Ron Anders

                                      More proof that some people have real problems. So stop complaining people, you could be Jörgen today.

                                      J Offline
                                      J Offline
                                      Jorgen Andersson
                                      wrote on last edited by
                                      #23

                                      Isn't it enough if I'm being me?

                                      Wrong is evil and must be defeated. - Jeff Ello

                                      D 1 Reply Last reply
                                      0
                                      • J Jorgen Andersson

                                        Because I want to have the data extracted into normalized tables.

                                        Wrong is evil and must be defeated. - Jeff Ello

                                        abmvA Offline
                                        abmvA Offline
                                        abmv
                                        wrote on last edited by
                                        #24

                                        if u have sql server there is SSIS anyway... [Importing XML documents using SQL Server Integration Services](https://www.mssqltips.com/sqlservertip/3141/importing-xml-documents-using-sql-server-integration-services/)

                                        Caveat Emptor. "Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long

                                        We are in the beginning of a mass extinction. - Greta Thunberg

                                        J 3 Replies Last reply
                                        0
                                        • abmvA abmv

                                          if u have sql server there is SSIS anyway... [Importing XML documents using SQL Server Integration Services](https://www.mssqltips.com/sqlservertip/3141/importing-xml-documents-using-sql-server-integration-services/)

                                          Caveat Emptor. "Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long

                                          J Offline
                                          J Offline
                                          Jorgen Andersson
                                          wrote on last edited by
                                          #25

                                          I've missed out on that possibility completely. A bit late now, but I'll take a look at it anyway. :thumbsup:

                                          Wrong is evil and must be defeated. - Jeff Ello

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups