Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello there. I really need help writing this python code for multiprocessing using the rsync command to fix a slow system. I've posted the question

image text in transcribedHello there.

I really need help writing this python code for multiprocessing using the rsync command to fix a slow system.

I've posted the question before but I guess I didn't attach enough details, so it got cancelled. Could you please help me write the code to solve the "dailysinc" issue.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Terminal Shell Edit View Window Help * 0 Fri Jan 15 12:36 AM appleowner - student-00-7f1572c49011@linux-instance: -- ssh -i -/Downlo... 0 googlecoursera.qwiklabs.com or directory (2) rsync error: some files/attrs were not transferred (see previous errors) (code 23) C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part... 4 Online Pytho at main.c(1196) [sender=3.1.2) 23 >>> exit() + Fix a slow system with Python student-00-7f1572c49011@linux-instance: $ ls /scripts dailysync.py multisync.py student-00-7f1572c49011@linux-instance: $ sudo chmod +x/multisync.py curu muyucur pivu w rua vu-VarP TUTUCI. student-00-7f1572c49011@linux-instance: $ ./scripts/multisync.py Handling taski Handling task2 End Lab 01:10:30 Handling task3 Hint: os.walk() generates the file names in a directory tree student-60-7f1572c49011@linux-instance: $ nano /scripts/dailysync.py student-00-7f1572c49011@linux-instance: $ sudo chmod +x m/scripts/dailysync.py top-down or bottom-up. This is used to traverse the file sys student-88-7f1572c49011@linux-instance: $ ./scripts/dailysync.py Caution: When you are in the console, do not rsync: change_dir "/data/prod" failed: No such file or directory (2) deviate from the lab instructions. Doing so rsync: mkdir "/data/prod_backup" failed: No such file or directory (2) rsync error: error in file Io (code 11) at main.c(675) [Receiver=3.1.2] may cause your account to be blocked student-00-7f1572c49011@linux-instance: $1 Learn more. Once you're done writing the Python script, save the file by Conny One, RIO Basics rsync command linux-instance external IP address key, and Ctrl-x. Multiprocessing 34.69.141.105 Copied! Now, grant the executable permission to the dailysync.py Python script for running Congratulations! this file. username End your lab student-20-7f1572c491 Copied! sudo chmod +x -/scripts/dailysync.py Download PEM Download PPK Run the dailysync.py Python script: ../scripts/dailysync.py Click Check my progress to verify the objective. Backup from production to production backup server Check my progress 15 tv 0 W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:04 AM https://googlecoursera.qwiklabs.com/focuses/47754 + 0 CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python Qwiklabs Multiprocessing in Python | Part 2 | pytho... + Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python Introduction Introduction Start Lab 01:30:00 -/5 Accessing the virtual machine CPU bound Basics rsync command You're an IT administrator for a media production company that uses Network- Attached Storage (NAS) to store all data generated daily (e.g., videos, photos). One of your daily tasks is to back up the data in the production NAS (mounted at /data/prod on the server) to the backup NAS (mounted at /data/prod_backup on the server). A former member of the team developed a Python script (full path /scripts/dailysync.py) that backs up data daily. But recently, there's been a lot of data generated and the script isn't catching up to the speed. As a result, the backup process now takes more than 20 hours to finish, which isn't efficient at all for a daily backup. Multiprocessing Congratulations! End your lab What you'll do Identify what limits the system performance: 1/0, Network, CPU, or Memory Use rsync command instead of cp to transfer data Get system standard output and manipulate the output Find differences between threading and multiprocessing You'll have 90 minutes to complete this lab. Start the lab JAN 15 (tv M W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:04 AM https://googlecoursera.qwiklabs.com/focuses/47754 + CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python | Qwiklabs Multiprocessing in Python | Part 2 | pytho... - Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python Connect to the VM using the local Terminal application Introduction Start Lab 01:30:00 -/5 A terminal is a program which provides a text-based interface for typing commands. Here you will use your terminal as an SSH client to connect with lab provided Linux Accessing the virtual machine VM. CPU bound Basics rsync command 1. Open the Terminal application. Multiprocessing To open the terminal in Linux use the shortcut key Ctrl+Alt+t. Congratulations! To open terminal in Mac (OSX) enter cmd + space and search for terminal. End your lab 2. Enter the following commands. Note: Substitute the path/filename for the PEM file you downloaded, username and External IP Address. You will most likely find the PEM file in Downloads. If you have not changed the download settings of your system, then the path of the PEM key will be ~/Downloads/qwikLABS-XXXXX.pem chmod 600 ~/Downloads/qwikLABS-XXXXX.pem 15 tv W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:04 AM https://googlecoursera.qwiklabs.com/focuses/47754 + CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python Qwiklabs Multiprocessing in Python | Part 2 | pytho... - Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python CPU bound Introduction Start Lab 01:30:00 -/5 Accessing the virtual machine CPU bound Basics rsync command CPU bound means the program is bottlenecked by the CPU (Central Processing Unit). When your program is waiting for 1/0 (e.g., disk read/write, network read/write), the CPU is free to do other tasks, even if your program is stopped. The speed of your program will mostly depend on how fast that I/O can happen; if you want to speed it up, you'll need to speed up the I/O. If your program is running lots of program instructions and not waiting for 1/0, then it's CPU bound. Speeding up the CPU will make the program run faster. Multiprocessing Congratulations! End your lab In either case, the key to speeding up the program might not be to speed up the hardware but to optimize the program to reduce the amount of I/O or CPU it needs. Or you can have it do I/O while it also does CPU-intensive work. CPU bound implies that upgrading the CPU or optimizing code will improve the overall computing performance. In order to check how much your program utilizes CPU, you first need to install the pip3 which is a Python package installer. This downloads and configures new Python modules with single-line commands. For any pop-up messages, when the prompt Do you want to continue appears, type 'Y'. sudo apt install python3-pip psutil (process and system utilities) is a cross-platform library for retrieving 15 ? Is (tv 00 W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:04 AM https://googlecoursera.qwiklabs.com/focuses/47754 + CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python | Qwiklabs Multiprocessing in Python | Part 2 | pytho... + Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python sudo apt install python3-pip Introduction Start Lab 01:30:00 -/5 Accessing the virtual machine CPU bound psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It's mainly useful for system monitoring, profiling, and limiting process resources and management of running processes. Install the psutil python library using pip3: Basics rsync command Multiprocessing pip3 install psutil Congratulations! End your lab Now open python3 interpreter. python3 Import psutil python3 module for checking CPU usage as well as the 1/0 and network bandwidth. import psutil psutil.cpu_percent() Output: gcpstaging100358_student@linux-instance: $ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) 15 ? Is tv W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:05 AM https://googlecoursera.qwiklabs.com/focuses/47754 + CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python | Qwiklabs Multiprocessing in Python | Part 2 | pytho... - Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python Output: Introduction Start Lab 01:30:00 -/5 Accessing the virtual machine CPU bound gcpstaging100358_student@linux-instance:-$ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import psutil >>> psutil.cpu_percent() 1.2 >>> exit() gcpstaging100358_student@linux-instance:-$ 1 Basics rsync command Multiprocessing Congratulations! This shows that CPU utilization is low. Here, you have a CPU with multiple cores; this means one fully loaded CPU thread/virtual core equals 1.2% of total load. So, it only uses one core of the CPU regardless of having multiple cores. End your lab After checking CPU utilization, you noticed that they're not reaching the limit. So, you check the CPU usage, and it looks like the script only uses a single core to run. But your server has a bunch of cores, which means the task is CPU-bound. Now, using psutil.disk_io_counters() and psutil.net_io_counters() you'll get byte read and byte write for disk 1/0 and byte received and byte sent for the network I/O bandwidth. For checking disk I/O, you can use the following command: psutil.disk_io_counters Output: 15 tv 00 W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:05 AM https://googlecoursera.qwiklabs.com/focuses/47754 + CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python | Qwiklabs Multiprocessing in Python | Part 2 | pytho... - Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python psutil.disk_io_counters() Introduction Start Lab 01:30:00 -/5 Accessing the virtual machine Output: CPU bound >> psutil.disk_io_counters() sdiskio[read_count=6234, write_count=25723, read_bytes=174928704, write_bytes=728805376, read_time=16292, write_tim e-225216, read_merged_count=e, write_nerged_count=2804e, busy_time=15144) Basics rsync command For checking the network I/O bandwidth: Multiprocessing Congratulations! psutil.net_io_counters() End your lab Output: >>> psutil.net_io_counters() snetio(bytes_sent=5377049, bytes_recv=1181422873, packets_sent=76538, packets_recv=79131, errin=8, errout=8, dropin EO, dropout=0) >>> exito Exit from the Python shell using exit(). After checking the disk 1/0 and network bandwidth, you noticed the amount of byte read and byte write for disk 1/0 and byte received and byte sent for the network I/O bandwidth. 15 ? I do (tv W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:05 AM https://googlecoursera.qwiklabs.com/focuses/47754 + CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python | Qwiklabs Multiprocessing in Python | Part 2 | pytho... - Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python Introduction Start Lab 01:30:00 -/5 Basics rsync command Accessing the virtual machine CPU bound Basics rsync command Multiprocessing rsync ( remote sync) is a utility for efficiently transferring and synchronizing files between a computer and an external hard drive and across networked computers by comparing the modification time and size of files. One of the important features of rsync is that it works on the delta transfer algorithm, which means it'll only sync or copy the changes from the source to the destination instead of copying the whole file. This ultimately reduces the amount of data sent over the network. Congratulations! End your lab The basic syntax of the rsync command is below: rsync [Options] [Source-Files-Dir] [Destination] Some of the commonly used options in rsync command are listed below: Options Uses -V Verbose output -9 Suppress message output -a Archive files and directory while synchronizing Sun files and directories recursival 15 ? Is tv 0 W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:05 AM https://googlecoursera.qwiklabs.com/focuses/47754 + CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python | Qwiklabs Multiprocessing in Python | Part 2 | pytho... + Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python Example: Introduction Start Lab 01:30:00 -/5 Accessing the virtual machine In order to use the rsync command in Python, use the subprocess module by calling call methods and passing a list as an argument. You can do this by opening the python3 shell: CPU bound Basics rsync command python3 Multiprocessing Congratulations! Now, import the subprocess module and call the call method and pass the arguments: End your lab import subprocess src = "" # replace with the source directory dest = "" # replace with the destination directory subprocess.call([ "rsync", "-arq", src, dest]) By using the above script, you can sync your data recursively from the source path to the destination path. Exit from the Python shell using exit(). 15 ? IS tv W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:06 AM https://googlecoursera.qwiklabs.com/focuses/47754 + 0 CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python Qwiklabs Multiprocessing in Python | Part 2 | pytho... - Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python Multiprocessing Introduction Start Lab 01:30:00 -/5 Accessing the virtual machine CPU bound Basics rsync command Now, when you go through the hierarchy of the subfolders of /data/prod, data is from different projects (e.g., , beta, gamma, kappa) and they're independent of each other. So, in order to efficiently back up parallelly, use multiprocessing to take advantage of the idle CPU cores. Initially, because of CPU bound, the backup process takes more than 20 hours to finish, which isn't efficient for a daily backup. Now, by using multiprocessing, you can back up your data from the source to the destination parallelly by utilizing the multiple cores of the CPU. Multiprocessing Congratulations! End your lab User practice Navigate to the script/ directory using the command below: ls -/scripts Output: gcpstaging100358_student@linux-instance:$ ls -/scripts dailysync.py multisync.py M Now, you'll get the Python script multisync.py for practice in order to understand how multiprocessing works. We used the Pool class of the multiprocessing Python 15 ? 100 (tv 0 W Safari File Edit View History Bookmarks Develop Window Help * G2 O Fri Jan 15 12:06 AM https://googlecoursera.qwiklabs.com/focuses/47754 + 0 CQwiklabs Assessment: Performance Tuni... Fix a slow system with Python | Qwiklabs Multiprocessing in Python | Part 2 | pytho... Online Python Interpreter - online editor Active Background Coding - UNIVERSE... + Fix a slow system with Python tasks as an argument. Introduction Start Lab 01:30:00 -/5 Now, grant executable permission to the multisync.py Python script for running this file. Accessing the virtual machine CPU bound sudo chmod +x -/scripts/multisync.py Basics rsync command Multiprocessing Run the multisync.py Python script: Congratulations! ./scripts/multisync.py End your lab Output: gcpstaging100358_student@linux-instance:-$ ./scripts/multisync.py Handling taski Handling task2 Handling task3 To learn more about multiprocessing, check out this link. User exercise Now that you understand how multiprocessing works, let's fix CPU bound so that it doesn't take more than 20 hours to finish. Try applying multiprocessing, which takes 15 ? IJO tv M 0 W Terminal Shell Edit View Window Help * Fri Jan 15 12:20 AM 0 googlecoursera.qwiklabs.com + a C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part.... + Online Python Interpreter - onli... Active Background Coding - U. Get Homework Help With Cheg.. OO appleowner - student-00-7f1572c49011@linux-instance: -- ssh -1 -/Dow... + Fix a slow system with Python Setting up python3-dev (3.5.3-1) ... Processing triggers for libc-bin (2.24-11+deb9u4) ... Processing triggers for sgml-base (1.29) ... you want to continue appears, type 'Y'. Processing triggers for systemd (232-25+deb9u12) ... (student-00-7f1572c49011@linux-instance: $ pip3 install psutil Collecting psutil End Lab 01:26:29 Downloading https://files.pythonhosted.org/packages/e1/b0/7276de53321c12981717 0/5 490516b7e612364f2cb372ee8901bd4a66a90%d7/psutil-5.8.0.tar.gz (47kB) sudo apt install python3-pip 100% L 471kB 2.5MB/s Building wheels for collected packages: psutil Caution: When you are in the console, do not Running setup.py bdist_wheel for psutil ... done deviate from the lab instructions. Doing so Stored in directory: /home/student-00-7f1572c49011/.cache/pip/wheels/65/65/52/ may cause your account to be blocked psutil (process and system utilities) is a cross-platform 85435fd86249ad96c3f5a3bac9e1533242251f8967fd78fdcd Learn more. Successfully built psutil information on running processes and system utilizatio Installing collected packages: psutil linux-instance external IP address Successfully installed psutil-5.8.0 network, sensors) in Python. It's mainly useful for syste (student-00-181572c49011@linux-instance: $ python3 Python 3.5.3 (default, Nov 18 2020, 21:09:16) 34.69.141.105 Copied! limiting process resources and management of running [GCC 6.3.0 20170516) on linux Type "help", "copyright", "credits" or "license" for more information. psutil python library using pip3: >>> import psutil [>>> psutil.cpu_percent() 0.0 student-20-7f1572c491 Copied! >>> pip3 install psutil username Download PEM Now open python3 interpreter. Download PPK python3 Import psutil python3 module for checking CPU usage as well as the I/O and network bandwidth. import psutil psutil.cpu_percent() 15 tv 0 W Terminal Shell Edit View Window Help * Fri Jan 15 12:21 AM 0 googlecoursera.qwiklabs.com + a 01:25:41 C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part... + Online Python Interpreter - onli... Active Background Coding - U. Get Homework Help With Cheg.. OO appleowner - student-00-7f1572c49011@linux-instance: -- ssh -i -/Dow... + Fix a slow system with Python (student-00-7f1572049011@linux-instance: $ pip3 install psutil ] 3 Collecting psutil Downloading https://files.pythonhosted.org/packages/e1/b0/7276de53321c12981717 490516b7e612364f2cb372ee8901bd4a66a000d7/psutil-5.8.0.tar.gz (470kB) Output: 100% 471kB 2.5MB/s Building wheels for collected packages: psutil End Lab Running setup.py bdist_wheel for psutil ... done 0/5 gcpstaging100358_student@linux-instance:-$ python3 Stored in directory: /home/student-00-7f1572c49011/.cache/pip/wheels/65/65/52/ Python 3.5.3 (default, Sep 27 2018, 17:25:39) 8543bfd86249ad96c3f5a3bac9e15332f2251f8967fd78fdcd [GCC 6.3.0 20170516] on linux Successfully built psutil Caution: When you are in the console, do not Type "help", "copyright", "credits" or "license" for Installing collected packages: psutil deviate from the lab instructions. Doing so >>> import psutil Successfully installed psutil-5.8.0 may cause your account to be blocked >>> psutil.cpu_percent() (student-00-7f1572c49011@linux-instance: $ python3 Learn more. 1.2 Python 3.5.3 (default, Nov 18 2020, 21:09:16) >>> exit() (GCC 6.3.0 20170516) on linux linux-instance external IP address gcpstaging100358_student@linux-instance:-$| Type "help", "copyright", "credits" or "license" for more information. >>> import psutil [>>> psutil.cpu_percent() 34.69.141.105 Copied! 0.0 This shows that CPU utilization is low. Here, you have a >>> psutil.disk_io_counters() means one fully loaded CPU thread/virtual core equals 6356736, read_time=16032, write_time=60924, read_merged_count=3, write_merged_co sdiskio(read_count=6487, write_count=25110, read_bytes=209523712, write_bytes=74 username uses one core of the CPU regardless of having multiple unt=28454, busy_time=12816) student-20-7f1572c491 Copied! 1 After checking CPU utilization, you noticed that they're not reaching the limit. Download PEM Download PPK So, you check the CPU usage, and it looks like the script only uses a single core to run. But your server has a bunch of cores, which means the task is CPU-bound. Now, using psutil.disk_io_counters() and psutil.net_io_counters() you'll get byte read and byte write for disk 1/0 and byte received and byte sent for the network I/O bandwidth. For checking disk 1/0, you can use the following command: psutil.disk_io_counters Output: 15 ? T = 7 tv 0 W 01:24:04 Terminal Shell Edit View Window Help * Fri Jan 15 12:22 AM OOO appleowner - student-00-7f1572c49011@li... 0 googlecoursera.qwiklabs.com Type "help", "copyright", "credits" or "license" for more information. C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part.... - Online Python Interpreter - onli... Activ >>> import psutil >>> psutil.cpu_percent() 0.0 + Fix a slow system with Python >>> psutil.disk_io_counters() sdiskio(read_count=6487, write_count=25110, read_byt es=209523712, write_bytes=746356736, read_time=16032 NOW, using psutil.disk_lo_counters and psutil.net_lo_counters you'll get byte read, write_time=68924, read_merged_count=3, write_merge d_count=28454, busy_time=12816) and byte write for disk 1/0 and byte received and byte sent for the network I/O [>>> psutil.net_io_counters() End Lab snetio(bytes_sent=996212, bytes_recv=129782469, pack bandwidth. For checking disk I/O, you can use the following command: ets_sent=10112, packets_recv=10310, errin=0, errout= , dropin=0, dropout=0) >>> Caution: When you are in the console, do not deviate from the lab instructions. Doing so psutil.disk_io_counters CPU bound may cause your account to be blocked. Learn more Basics rsync command linux-instance external IP address Output: Multiprocessing 34.69.141.105 Copied! >> psutil.disk_io_counters() sdiskio(read_count=6234, write_count=25723, read_bytes=174928704, write_bytes=728805376, read_time=16292, write_tim e=225216, read_merged_count=e, write_nerged_count=28040, busy_time=15144) Congratulations! username End your lab student-20-7f1572c491 Copied! For checking the network 1/0 bandwidth: Download PEM psutil.net_io_counters Download PPK Output: >>> psutil.net_io_counters() snetio(bytes sent=5377049, byt bytes_recv=1181422873, packets_sent=76538, packets_recv=79131, errin=8, errout=e, dropin =o, dropout=0) >>> exit() Exit from the Python shell using exit(). After checking the disk 1/0 and network bandwidth, you noticed the amount of byte read and byte write for disk 1/0 and byte received and byte sent for the network I/O bandwidth 15 ? tv M ce W Terminal Shell Edit View Window Help * O Fri Jan 15 12:24 AM Example: OOO appleowner - student-00-7f1572c49011@li... 0 googlecoursera.qwiklabs.com Type "help", "copyright", "credits" or "license" for more information. C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part... 4 Online Python Interpreter - onli... Activ >>> import subprocess >>> src = "" # replace wi th the source directory + Fix a slow system with Python [>>> dest = "" # replace with the destination directory [>>> subprocess.call(["rsync", "-arq", src, dest]) rsync: link_stat "/home/student-00-7f1572c49011/" failed: No such file or directory (2) rsync error: some files/attrs were not transferred ( End Lab 01:22:56 see previous errors) (code 23) at main.c(1196) [send er=3.1.2] In order to use the rsync command in Python, use the subprocess module by calling 23 >>> Caution: When you are in the console, do not call methods and passing a list as an argument. You can do this by opening the deviate from the lab instructions. Doing so python3 shell: CPU bound may cause your account to be blocked. Learn more. Basics rsync command linux-instance external IP address python3 Multiprocessing 34.69.141.105 Copied! Congratulations! username Now, import the subprocess module and call the call method and pass the arguments: End your lab student-20-7f1572c491 Copied! Download PEM import subprocess src = "" # replace with the source directory dest = "" # replace with the destination directory Download PPK subprocess.call([ "rsync", "-arq", src, dest]) By using the above script, you can sync your data recursively from the source path to the destination path. Exit from the Python shell using exit(). 15 ? Is tv 0 W Terminal Shell Edit View Window Help * ta Fri Jan 15 12:25 AM 0 googlecoursera.qwiklabs.com C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part... - Online Python Interpreter - onli... + Fix a slow system with Python O appleowner - student-00-7f1572c49011@li.. on-path> with the destination directory [>>> subprocess.call(["rsync", "-arq", src, dest]) Active Back rsync: link_stat "/home/student-00-7f1572c49011/" failed: No such file or directory (2) rsync error: some files/attrs were not transferred ( see previous errors) (code 23) at main.c(1196) [send er=3.1.2] 23 [>>> exit() (student-00-7f1572c49011@linux-instance: $ ls -/scrip] ts dailysync.py multisync.py (student-00-7f1572c49011@linux-instance: $ sudo chmod] +x/scripts/multisync.py student-00-7f1572c49011@linux-instance: $1 Navigate to the script/ directory using the command below: End Lab 01:21:52 ls -/scripts CPU bound Caution: When you are in the console, do not deviate from the lab instructions. Doing so may cause your account to be blocked Learn more. Output: Basics rsync command linux-instance external IP address gcpstaging100358_student@linux-instance:-$ ls -/scripts dailysync.py multisync.py Multiprocessing 34.69.141.105 Copied! Congratulations! username End your lab student-20-7f1572c491 Copied! Now, you'll get the Python script multisync.py for practice in order to understand how multiprocessing works. We used the Pool class of the multiprocessing Python module. Here, we define a run method to perform the tasks. Next, we have a few tasks. Create a pool object of the Pool class of a specific number of CPUs your system has by passing a number of tasks you have. Start each task within the pool object by calling the map instance method, and pass the run function and the list of tasks as an argument. Download PEM Download PPK Now, grant executable permission to the multisync.py Python script for running this file. sudo chmod +x ~/scripts/multisync.py Run the multisync.py Python script: 15 ? 10 (tv 0 W 01:21:09 Terminal Shell Edit View Window Help * ta Fri Jan 15 12:25 AM O appleowner - student-00-7f1572c49011@li... 0 googlecoursera.qwiklabs.com see previous errors) (code 23) at main.c(1196) (send er=3.1.2] C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part... - Online Python Interpreter - onli... Active Back 23 [>>> exit() (student-00-7f1572c49011@linux-instance: $ ls /scrip] ts + Fix a slow system with Python dailysync.py multisync.py (student-00-7f1572c49011@linux-instance: $ sudo chmod] +x/scripts/multisync.py (student-00-7f1572c49011@linux-instance: $ ./scripts/] Now, grant executable permission to the multisync.py Python script for running multisync.py End Lab Handling task1 this file. Handling task2 Handling task3 student-00-7f1572c49011@linux-instance: $ 1 Caution: When you are in the console, do not deviate from the lab instructions. Doing so sudo chmod +x -/scripts/multisync.py CPU bound may cause your account to be blocked Learn more Basics rsync command linux-instance external IP address Run the multisync.py Python script: Multiprocessing 34.69.141.105 Copied! ./scripts/multisync.py Congratulations! username End your lab student-20-7f1572c491 Copied! Output: Download PEM Download PPK gcpstaging100358_student@linux-instance:-$ ./scripts/multisync.py Handling task1 Handling task2 Handling task3 To learn more about multiprocessing, check out this link. User exercise Now that you understand how multiprocessing works, let's fix CPU bound so that it doesn't take more than 20 hours to finish. Try applying multiprocessing, which takes advantage of the idle CPU cores for parallel processing. 15 ? Is tv W Terminal Shell Edit View Window Help * Ga 0 2 Fri Jan 15 12:26 AM 0 googlecoursera.qwiklabs.com OOO appleowner - student-00-7f1572c49011@li.. ...ent-00-7f1572c49011/scripts/dailysync.py Modified C Qwiklabs Assessment: Perform... Fix a slow system with Python ... Multiprocessing in Python | Part... - Online Python Interpreter - onli... Active !/usr/bin/env python import subprocess src = "/data/prod/" dest = "/data/prod_backup/" subprocess.call(["rsync", "-arq", src, dest]) + Fix a slow system with Python It's similar to multisync.py that utilizes idle CPU cores for the backup. End Lab 01:20:13 nano -/scripts/dailysync.py Caution: When you are in the console, do not deviate from the lab instructions. Doing so may cause your account to be blocked. Learn more. CG Get Help ^X Exit o Write Out Where Is Read File Replace Basics rsync command Cut Text Uncut Text Here, you have to use multiprocessing and subprocess module methods to sync the data from /data/prod to /data/prod_backup folder. linux-instance external IP address Multiprocessing 34.69.141.105 Copied! Hint: os.walk() generates the file names in a directory tree by walking the tree either top-down or bottom-up. This is used to traverse the file system in Python. Congratulations! username End your lab student-20-7f1572c491 Copied! Once you're done writing the Python script, save the file by clicking Ctrl-o, the Enter key, and Ctrl-x. Download PEM Download PPK Now, grant the executable permission to the dailysync.py Python script for running this file. sudo chmod +x ~/scripts/dailysync.py Run the dailysync.py Python script: ./scripts/dailysync.py 15 stv M 0 W

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data With Hadoop MapReduce A Classroom Approach

Authors: Rathinaraja Jeyaraj ,Ganeshkumar Pugalendhi ,Anand Paul

1st Edition

1774634848, 978-1774634844

More Books

Students also viewed these Databases questions

Question

Have you been rather narrow-minded in considering possibilities?

Answered: 1 week ago

Question

I receive useful feedback about my performance.

Answered: 1 week ago

Question

I am encouraged to offer opinions/suggestions.

Answered: 1 week ago