CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.

Slides:



Advertisements
Similar presentations
Detecting Bugs Using Assertions Ben Scribner. Defining the Problem  Bugs exist  Unexpected errors happen Hardware failures Loss of data Data may exist.
Advertisements

1 CS 194: Elections, Exclusion and Transactions Scott Shenker and Ion Stoica Computer Science Division Department of Electrical Engineering and Computer.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Remote Procedure Call (RPC)
EEC 688/788 Secure and Dependable Computing Lecture 12 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
Debugging Introduction to Computing Science and Programming I.
David Notkin Autumn 2009 CSE303 Lecture 7 bash today, C tomorrow Quick reprise: debugging, performance What’s homework 2B? (yes, it’s posted) Some looks.
Database Replication techniques: a Three Parameter Classification Authors : Database Replication techniques: a Three Parameter Classification Authors :
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Computer Science 162 Section 1 CS162 Teaching Staff.
EEC 693/793 Special Topics in Electrical Engineering Secure and Dependable Computing Lecture 12 Wenbing Zhao Department of Electrical and Computer Engineering.
Building Secure Software Chapter 9 Race Conditions.
16/27/2015 3:38 AM6/27/2015 3:38 AM6/27/2015 3:38 AMTesting and Debugging Testing The process of verifying the software performs to the specifications.
Debugging CMSC 201. Announcements Hw2, Hw3 grades returned if something doesn’t seem right, ask Midterm next Thurs (Oct 23) we’ll review on Tues no hw.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Fundamentals of Python: From First Programs Through Data Structures
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
Programming Network Servers Topic 6, Chapters 21, 22 Network Programming Kansas State University at Salina.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Using a Debugger. SWC What is ”debugging”? An error in a computer program is often called a ”bug”… …so, to ”debug” is to find and get rid of errors in.
TESTING.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Nachos Phase 1 Code -Hints and Comments
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
1 Welcome to CS 362 Applied Software Engineering What happens after (and during) design? Testing, debugging, maintaining programs Lessons for software.
General Programming Introduction to Computing Science and Programming I.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
Games Development 2 Concurrent Programming CO3301 Week 9.
Debugging Strategies from Software Carpentry. Agan's Rules Many people make debugging harder than it needs to be by: Using inadequate tools Not going.
Systems Life Cycle. Know the elements of the system that are created Understand the need for thorough testing Be able to describe the different tests.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Threads Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment?
Software Engineering 2004 Jyrki Nummenmaa 1 BACKGROUND There is no way to generally test programs exhaustively (that is, going through all execution.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
Data Structure Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2010.
Error Handling Tonga Institute of Higher Education.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Source Level Debugging of Parallel Programs Roland Wismüller LRR-TUM, TU München Germany.
MULTIVIE W Slide 1 (of 21) Software Transactional Memory Should Not Be Obstruction Free Paper: Robert Ennals Presenter: Emerson Murphy-Hill.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 486/586 CSE 486/586 Distributed Systems Global States Steve Ko Computer Sciences and Engineering University at Buffalo.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Agenda  Quick Review  Finish Introduction  Java Threads.
CSE 486/586 CSE 486/586 Distributed Systems Leader Election Steve Ko Computer Sciences and Engineering University at Buffalo.
Exploring Taverna engine Aleksandra Pawlik materials by Katy Wolstencroft University of Manchester.
Advanced Taverna Aleksandra Pawlik University of Manchester materials by Katy Wolstencroft, Aleksandra Pawlik, Alan Williams
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
Taverna allows you to automatically iterate through large data sets. This section introduces you to some of the more advanced configuration options for.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
6/27/20161 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Paxos Steve Ko Computer Sciences and Engineering University at Buffalo.
Tutorial 2: Homework 1 and Project 1
CSE 486/586 Distributed Systems Consistency --- 2
Reactive Android Development
CSE 486/586 Distributed Systems Leader Election
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Testing and Debugging.
Multiple Writers and Races
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
Some Simple Definitions for Testing
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Algorithm and Ambiguity
CSE 486/586 Distributed Systems PA Best Practices
January 15, 2004 Adrienne Noble
Presentation transcript:

CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo

CSE 486/586 First Things to Keep in Mind Your implementation is necessarily going to be full of bugs. –Your job is to reduce the number of bugs as many as possible before submitting it. Correctness first. Performance later. –Don’t even think about performance optimization in your first-cut implementation. You will not do it correctly. Know how to use sockets precisely. –What does accept() do? What is a port number? What is socket timeout? What do read(), write(), and flush() do? –There is no other way but reading the documentation thoroughly. 2

CSE 486/586 First Things to Keep in Mind Know the constructs and data structures precisely. –AsyncTasks, Threads, Cursors, etc. –Once again, read the documentation thoroughly. Write your code systematically. –Write a small chunk, test, and repeat. Structure your code well. Simplify. –Use simple, one-shot tasks (e.g., request-response) that work independently, asynchronously, and mostly serially. –A rule to compare: if your method has more than 20 lines, think why you’re doing it and convince yourself that it’s necessary. 3

CSE 486/586 First Things to Keep in Mind Embrace concurrency –Dealing with concurrency is your make-or-break point for all later assignments. –Keep in mind that your code will behave in a non- deterministic way with multiple threads. –We still expect your code to produce deterministic results. –You will need to come up with your own test cases and testing strategies (more on this later). –You will need to run the graders multiple times and make sure that you get the same results consistently. Serialize as much as possible. –Do one thing at a time. –Use a lock on every shared variable. 4

CSE 486/586 First Things to Keep in Mind Don’t be caught up with just one way of doing things. –Start early. –Ask and explore if there is any other way of doing the same thing. –Learn why one way is better than the other. –This often results in a better, faster outcome. Use logging statements for debugging. –Almost the only way to debug things for distributed systems. –Once deployed, the only way to debug your code in any system. –Open logcat for each instance in a terminal. –It’s OK to put a lot of logging statements. Just remove really unnecessary ones later. –Be aware that logging statements alter the code behavior. 5

CSE 486/586 First Things to Keep in Mind Do not use graders as your debugger. –Graders do not know what you’re doing. They only verify what you’re returning. –They will try to give you reasons why they are complaining. But this by no means gives you enough information for debugging. –When a grader complains about something, you need to look at your own logs and pinpoint what’s going on. 6

CSE 486/586 First Things to Keep in Mind Do not assume that Android or graders are broken. –It’s almost always your code. Blaming other systems only reveals your immaturity as a developer –In general, if you’re developing with a large-scale system, it’s always tempting to think that the other system is broken, not yours. –That’s almost always wrong, unless you have a very well- thought-out reason verified by people knowledgeable about the internals of the other system. 7

CSE 486/586 First Things to Keep in Mind You will write complex code, so make sure that you have your own testing strategy –Graders are convenient, indeed. However, it is just not enough for testing and debugging. –This is especially true with concurrency, since a bug may not manifest deterministically. There can be many conditions that lead to deadlocks and livelocks. –It’s best to develop your own test cases that stress your system. 8

CSE 486/586 More Specific Things Socket –Know how exactly it works. E.g., accept() returns a new socket. –Know how to use socket timeout, which only times out when reading (not writing, not accepting, etc.). –Use it as a write/read pair (and check on the returning read for failures), or even better, continue using the same socket as long as possible. AsyncTask –Be aware: there is a limit of how many you can create and execute at the same time (a concept called thread pools). This is system-dependent, but on our emulator, it seems to be 5. –You can wait for a result using AsyncTask.get() 9

CSE 486/586 More Specific Things Threading –Understand how threads behave and synchronization works. E.g., what happens if you call Thread.sleep() in the middle of an execution? What happens with wait() and notify()? –If you have threads, but don’t use locks or synchronized, you’re probably doing something very wrong. Messages –Do not send a whole object (Serializable). Takes a long time, unnecessarily big, and just a lot of overhead. –Formatted strings should be enough. 10

CSE 486/586 More Specific Things Logging –Concurrency is difficult to debug and extensive logging is pretty much the only reliable way. –You need to be able to trace out all interactions, e.g., communication originated from one peer to all other peers and coming back (use and log message IDs, message types, etc.) –You need to be able to keep track of each thread’s progress, e.g., is this method call blocked or returning? Is this for loop moving on to the next iteration? Is this loop terminating properly? Know how to use adb –adb devices –adb kill-server/start-server –adb install/uninstall/insert/query 11

CSE 486/586 More Specific Things Grader related –Check the output of a grader carefully. They do not always print out a potential error at the end. –Graders use string matching to check the results. Be careful about extra whitespaces you might be inserting. onCreate() –This should not do any long-running operation. If onCreate() takes a long time to return, it might give you unexpected problems, e.g., it might get called multiple times. –This is especially true with a ContentProvider. If onCreate() is being executed and there’s an insert() or a query() call, onCreate() will be called again. 12

CSE 486/586 More Specific Things Callback method signatures –Do not change the signature of a callback method you implement, e.g., query(), insert(), etc. They are all defined by Android, and Android doesn’t expect any change. –For example, don’t add synchronized to query() or insert(). It will behave in an erratic way. Failure detection –You can use a regular request/reply as a failure detection mechanism. –For this, always reply back with something so the other side knows that you’re alive. 13