Wednesday, 15 December 2010

Performance : A few tips that worth to implement.

 
These tips will help you have faster applications, and most of that are to be implemented with Java.
1 - Client (UI) should (must) be thin client :
Don’t create client that do too many things, specially DAO to load reference tables each time that you need load the page. Thin client should do basic validation just to have data integrity, like date formats and range, numbers ranges, if that field can accept null or not, business rules as the name say should be performed in business. If you have one screen with multiple tabs, try create it as separate, JSP/XHTML pages, for page to each one tab, with independent validations happening just before you jump to the next tab, and go passing the object populated till you get into the submit page. Doing this, you will load few objects each time in memory and smaller pages too. Try keep at minimum those submits, most of instance variables that aren’t being used should be set to null, with this the GC will collect them faster.  There are a lot to talk about thin client, actually exist books talking about it, though if you follow this, will help you a lot with performance. UI should never make call to DAO, everything should come ready from Business layer, if you need keep those drop down lists updated all the time, use cache and dependency injection (old IOC) in business layer to keep those caches updated.

     
2 – JPA/Hibernate mappings, should be consistent, with database design
I know that today we have ORM, though a lot of people see it as a recipe to ignore all good practices about relationship. What I can tell here is respect the  entity-relationship, and use lazy, or if you do need just one data, and this data is strictly necessary, perform one single and simple read using native query in that table. The database design, I mean internally is made to work using entity-relationship, and if you create it in creation time, you should use it to have the best performance with it. I’m not saying that ORM will be bad to performance, but it bad when everybody that has to implement one new feature, create one new ORM relationship that doesn’t follow what the database was designed for, and with it after some time start being really hard fix it, due a lot of mapping and code has to be changed. Try keep it simple and functional without implement to many mapping-relationship with no need. If you need for many things and you have good reasons to use it further so implement it, now if it’s just for one or two things, don’t do it.

3 - JSF 1.2 and Facelets are good
Actually are awesome, they are so good that JSF 2, is 1.2 with improvements and Facelets,  the biggest problem is the way those systems were designed, a lot of people doesn’t really know JSF and Facelets properly and they instead read more about it and look for good implementations, they use the easiest one got from internet, or try use it as the old Struts work, that’s as action based framework, and in the end they have one very hard to maintain system, bloated with more layers than needed and with bad performance.


4 – Objects in memory, control them, use just the necessary
There a lot system that load a lot objects in memory without use, they keep in there up to they are needed, or worst the load several times the same object in memory with different instance names. Think this way, it’s better one big object in memory than several smaller ones using the same amount of memory, just because you consume less resources from you processor, doing the GC work less checking all the time what is needed to be collected. One rule of thumb is if you will need update just a few fields from one object, don’t load another in memory and then in the end merge them. Use local objects, that will be destroyed as soon the task is completed, try use primitive types in memory and then “persist” then into the object. Think that if your system is part of one enterprise one, not all resources will be available all the time like in your personal environment. There your system such probably will work together with several others systems all them consuming resources from server or servers, all them using the same memory, IO and everything else. Try use static to all those methods that make part of validations, this can cause some sort of bottleneck though will avoid memory leaks, and several instances that doesn’t being used in memory. Try keep the design clean, something like having one object for the screen, that will be converted after submit to BO and that the persistence layer in the end will split it and them persist into database.


5 – Avoid to use Strings
Instead use StringBuffer or StringBuilder, and preferably instantiate quite few and reusing it always as needed. Try use static ones, and “don’t use this” in comparations, print’s, since that it will never change. Use java standards to create names.


6 – Database connection, is the most expense resource that you will have
Even today I see a lot of system using DAO the wrong way, and most of them never have heard about use caches. The just let the AS take care of everything (as if should work). One good idea make the DAO layer one little bigger than just only CRUD operations. Try read about JPO (Java Persistence Objects), roughly speaking DAO should give to Business layer the BO ready and not in parts, entities alone for that Business has to convert it and discover soon after that will need again one other read (or several others) to complete the request. Loading or doing all necessary reads and populating once the BO object it’s good also because will open the connection just once, do everything needed and then close, maybe you don’t know about it though if you are using one data source your AS is doing it for you.


7 – Use of Web Services
They make a lot of sense if you have several technologies that should consume your system, if using just Java, try use serialized objects that is quite faster. Worth take a look into the granularity of those WS’s to check if some parts of it can be used for others services. But is essential that you migrate to WS those “services” that will doesn’t change very often and in rare cases create WS (WSDL) that will carry on huge objects as request and response.

8 – Have the most close environment as production in one machine
This’s really important thing, that will can test several settings to memory, data sources, and to check as your system is consuming the machine resources, and it’s good too to perform stress tests. Just making one good tunning in your AS will grant you at least 40% improvement in performance.Tweaking your AS will make a big difference.

9 – Don’t leave instance variables that aren’t being used to be collected to GC.
If you set as null every time that you will not use it anymore, will save a lot of resources from your machine.

The basic thing that you must have in mind is that in production very often all machine resources are shared among other systems, OS, AS, and that you can’t just go consuming it without think in consequences, and that there is not like in your machine, that when need perform one IO or use more memory is just do it, most of the cases the database is not in the same machine that your system, think always in economy of machine resources. That will make your system perform with performance.
There are a lot more rules that should be followed to have a good performance, though those are the main ones.
If you that are reading it have anything  to add please feel free to put comments.

Sunday, 3 October 2010

Persistence Domain Objects and Some Good Practices

In this post I’ll talk about Business layer, PDO and a few tips that will help you to have less complexity into Business layer and have one Persistence layer that will delivery data's ready to use for the Business layer.

Today most of Business Domain follow roughly this pattern:

actual_BD_chart

Where the Persistence layer is just for DAO, that is nothing wrong with it, but it doesn’t delivery data’s ready to use for the business, and because of this, it gives you one swelled Business layer, where does more than just business, especially with data's that come from Client side and Persistence layer, that’s needed convert then from entities to BO’s and then to TO’s  (or the old DTO’s). This’ telling me that the Business layer is doing more than just business is doing something else than business, where it should only take care of how data’s should be manipulated  and returning the result. Business layer shouldn't know about Persistence, should just make one call like getCustomerBO(); and work with it, not like is today, where’s needed populate all entity's then ‘filter’ the data that is needed to create those BO’s, then work with data’s and then populate those TO’s to return the result to the Client side.

One good idea that’s for sure will make your Business layer more thin, easy to maintain and performing just business tasks. Is model your application with real objects and don’t care about the Persistence layer at beginning. Real Objects means cohesive classes with encapsulated state, related behaviour and inheritance. Putting just business logic into the domain business objects, using inheritance where appropriate.

To resolve this we have an alternative that is move the convertor and BO’s to the persistence layer, and then your Business Domain will looks like this chart :

ideal_BD_chart

Following this your persistence layer will delivery BO’s ready to use for the Business layer.

In the next post I’ll go post here one very small example of this implementation.

Sunday, 26 September 2010

NoSQL – One Simple CRUD Example

Here I’d will explain how simple, with the right .jars, is work with NoSQL, in my example will be used the CouchDB, that is pretty simple and easy to install and make it run. Basically just unzip it and run the .bat file.  For any other explanations about NoSQL databases please go to this llink, or to this other one.

.jar’s that you will might need

Couch4j
Json lib
ezmorph
httpClient and httpCore

Here we’ll create one very simple example with simple table and no relationships.

Field name

_id
_rev
EMPLOYEE_ID
FIRST_NAME
FAMILY_NAME
GROUP
FUNCTION

We don’t need to worry with the field types due that the document, is a JSON object so, just strings and you must perform the conversions later on. Here one simple JSON document as example:

{
 "_id":"1",
 "_rev":"1-10",
 "EMPLOYEE_ID":"0001",
 "FIRST_NAME":"MyFirstName",
 "FAMILY_NAME":"MyFamilyName",
 "GROUP ":"JAVA",
 "FUNCTION":"Developer"
 }




CouchDB reserve those fields starting with _ (underscore) to be used to itself, e. g. : _id , and the _id itself is a primary key.


As I’m using the CouchDB as localhost and the default port to access it is 5984, and to do any sort of access into CouchDB you must have one session created, in other words session is mandatory.


   1:  package au.com.nosql.main;
   2:   
   3:  import com.fourspaces.couchdb.Database;
   4:  import com.fourspaces.couchdb.Document;
   5:  import com.fourspaces.couchdb.Session;
   6:  import com.fourspaces.couchdb.ViewResults;
   7:  import java.util.List;
   8:   
   9:  public class NoSQLMain {
  10:   
  11:     public static void main(String[] args) {
  12:        boolean exist = false;
  13:        Database db = null;
  14:        
  15:        // Creating the session
  16:        Session mySession = new Session("localhost", 5984);
  17:        String dbname = "employeeTest";
  18:   
  19:   
  20:   
  21:        // Check if the database already exist, if not create
  22:        // Including one document into my new database
  23:        List<String> dbsNames = mySession.getDatabaseNames();
  24:        for (String dbName : dbsNames) {
  25:           if (dbName.trim().equalsIgnoreCase(dbname)) {
  26:              System.out.println("Already exist the database with name" + dbname);
  27:              exist = true;
  28:              break;
  29:           }
  30:        }
  31:   
  32:        if (!exist) {
  33:           mySession.createDatabase(dbname);
  34:        }
  35:   
  36:        db = mySession.getDatabase(dbname);
  37:   
  38:        // create one document and save it
  39:        Document doc = new Document();
  40:        doc.setId("1");
  41:        doc.put("EMPLOYEE_ID", "0001");
  42:        doc.put("FIRST_NAME", "MyFirstName");
  43:        doc.put("FAMILY_NAME", "MyFamilyName");
  44:        doc.put("GROUP", "JAVA");
  45:        doc.put("FUNCTION", "Developer");
  46:             
  47:        db.saveDocument(doc);
  48:        doc = null;
  49:   
  50:        // Retrive that list of DBs
  51:        List<String> listofdb = mySession.getDatabaseNames();
  52:        System.out.println("Number Total Of Databases: " + listofdb.size());
  53:   
  54:        // Displaying the current number of documents
  55:        int count = db.getDocumentCount();
  56:        System.out.println("Total Documents: " + count);
  57:   
  58:        // Retriving a single document
  59:        Document getOne = db.getDocument("1");
  60:        System.out.println("Document returned from database : " + getOne.toString());
  61:        getOne = null;
  62:   
  63:        // Delete the document from Database
  64:        getOne = db.getDocument("1");
  65:        db.deleteDocument(getOne);
  66:        count = db.getDocumentCount();
  67:        System.out.println("Total Documents after delete : " + count);
  68:        getOne = null;
  69:   
  70:   
  71:        // cleaning all docs if exist more than one
  72:        ViewResults viewResults = db.getAllDocuments();
  73:        List<Document> docs = viewResults.getResults();
  74:        for(Document doc1 : docs) {
  75:           System.out.println("Document to be deleted : " + doc1.toString());
  76:           db.deleteDocument(doc1);
  77:        }
  78:   
  79:   
  80:        // Delete the database
  81:        mySession.deleteDatabase(dbname);
  82:        listofdb = mySession.getDatabaseNames();
  83:        System.out.println("Number Total Of Databases after delete that created one : " + listofdb.size());
  84:   
  85:     }
  86:  }




 


There is one other way to persist one NoSQL DB is using HTTP:


HttpClient httpclient = new DefaultHttpClient();
 
HttpGet get = new HttpGet("http://localhost:5984/employeeTest/_all_docs?startkey=%221%22&limit=1");
 
HttpResponse response = httpclient.execute(get);



 


Or :

HttpGet get = new HttpGet(http://localhost:5984/employeeTest/_all_docs?startkey=%223%22&endkey=%226%22)





Where %22 is used for single cote ( ‘ ).


One last thing, have in mind that CouchDB is not a relational database, so it will just allow querying data based on "key" only, so we cannot retrieve data based on field values from such databases.


This is just a simple example using CouchDB and with one very simple table structure, though for more complex things, as the DB is not relational you will need search using keys and then populate it to create what you might need.

Thursday, 16 September 2010

XStream – One example

Here I'll talk about my last experience using the small, however very powerful marshalling/unmarshalling XML framework, the Xstream, you can check it out into http://xstream.codehaus.org/ .
First of all, this framework has a very small API, especially for persistence and it's very powerful and fast to export your objects for one XML file, though to read it you need use JAXP, JAXB, IO or ant other library that read XML code, even the NIO from Java 6 will work.
You can download the binaries from here.
After unzip the file in your choose destination, you will have into the folder this tree, here in my case I'm using the version 1.3.1 :

xstream-1.3.1    
  doc API's and tutorials
  libs .jars / libs
  LICENSE.txt Text files
  README.txt Text files


You will require xstream-[version].jar and xpp3-[version].jar in the classpath. XPP3 is a very fast XML pull-parser implementation. If you do not want to include this dependency, you can use a standard JAXP DOM parser instead.

And here our bind classes, pojos :


ShipTo.java :

public class ShipTo {
    private String name;
    private String address;
    private String city;
    private String country;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getCountry() {
        return country;
    }
    public void setCountry(String country) {
        this.country = country;
    }
} 



 


Item.java :


public class Item {
    private String title;
    private String note;
    private String quantity;
    private String price;
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
    public String getQuantity() {
        return quantity;
    }
    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }
    public String getPrice() {
        return price;
    }
    public void setPrice(String price) {
        this.price = price;
    }
} 



 

ShipOrder.java :

public class ShipOrder {
    private String orderid;
    private String orderperson;
    private ShipTo shipto;
    private List<Item> item;
    public String getOrderid() {
        return orderid;
    }
    public void setOrderid(String orderid) {
        this.orderid = orderid;
    }
    public String getOrderperson() {
        return orderperson;
    }
    public void setOrderperson(String orderperson) {
        this.orderperson = orderperson;
    }
    public ShipTo getShipto() {
        return shipto;
    }
    public void setShipto(ShipTo shipto) {
        this.shipto = shipto;
    }
    public List<Item> getItem() {
        return item;
    }
    public void setItem(List<Item> item) {
        this.item = item;
    }
} 



 


Now our class that will serialize to one String as XML and then de-serialize to Objects.


   1:  /*
   2:   * To change this template, choose Tools | Templates
   3:   * and open the template in the editor.
   4:   */
   5:  package xstreamtest;
   6:   
   7:  import com.thoughtworks.xstream.XStream;
   8:  import java.util.ArrayList;
   9:  import java.util.List;
  10:   
  11:  /**
  12:   *
  13:   * @author Klaus
  14:   */
  15:  public class Main {
  16:   
  17:     /**
  18:      * @param args the command line arguments
  19:      */
  20:     public static void main(String[] args) {
  21:        // Getting the Xstream
  22:        XStream xstream = Main.getStream();
  23:   
  24:        // Serializing the object to XML
  25:        ShipTo shipTo = Main.getShipTo();
  26:        List<Item> listOfItems = Main.getItems();
  27:        ShipOrder shipOrder = Main.getShipOrder(shipTo, listOfItems);
  28:   
  29:        // Serializing to the XML into one String, can create file if you want it.
  30:        String shipOrderXml = xstream.toXML(shipOrder);
  31:   
  32:        // Display the XML created
  33:        System.out.println("The XML :");
  34:        System.out.println(shipOrderXml);
  35:   
  36:        // Populating the obj again
  37:        ShipOrder shipOrder1 = (ShipOrder) xstream.fromXML(shipOrderXml);
  38:        ShipTo shipTo1 = shipOrder1.getShipto();
  39:        List<Item> listOfItems1 = shipOrder1.getItem();
  40:   
  41:        System.out.println("-------------------------------");
  42:        System.out.println("- Desirializing to the object -");
  43:        System.out.println("-------------------------------");
  44:        System.out.println("Order Id     : " + shipOrder1.getOrderid());
  45:        System.out.println("Order Person : " + shipOrder1.getOrderperson());
  46:        System.out.println("Ship To      : " + shipOrder1.getShipto().getName());
  47:        System.out.println("Items : ");
  48:        for (Item item : listOfItems1) {
  49:           System.out.println("Title : " + item.getTitle());
  50:           System.out.println("Qtde. : " + item.getQuantity());
  51:           System.out.println("Price : " + item.getPrice());
  52:           System.out.println("Note  : " + item.getNote());
  53:           System.out.println("-----------------------------------------");
  54:        }
  55:     }
  56:   
  57:     public static XStream getStream() {
  58:        XStream xstream = new XStream();
  59:        xstream.alias("shipTo", ShipTo.class);
  60:        xstream.alias("item", Item.class);
  61:        xstream.alias("shipOrder", ShipOrder.class);
  62:        return xstream;
  63:     }
  64:   
  65:     public static List<Item> getItems() {
  66:        List<Item> items = new ArrayList<Item>();
  67:        Item item = new Item();
  68:        item.setTitle("Item 01");
  69:        item.setPrice("10.00");
  70:        item.setQuantity("5");
  71:        item.setNote("This is the first item");
  72:        items.add(item);
  73:   
  74:        item = new Item();
  75:        item.setTitle("Item 02");
  76:        item.setPrice("15.00");
  77:        item.setQuantity("7.50");
  78:        item.setNote("This is the second item");
  79:        items.add(item);
  80:   
  81:        return items;
  82:     }
  83:   
  84:     public static ShipTo getShipTo() {
  85:        ShipTo shipTo = new ShipTo();
  86:        shipTo.setName("Customer 01");
  87:        shipTo.setCity("City 01");
  88:        shipTo.setCountry("country 01");
  89:        shipTo.setAddress("Address 01");
  90:        return shipTo;
  91:     }
  92:   
  93:     public static ShipOrder getShipOrder(ShipTo shipTo, List<Item> items) {
  94:        ShipOrder so = new ShipOrder();
  95:        so.setOrderid("Order number 01");
  96:        so.setOrderperson("Order to Person 01");
  97:        so.setShipto(shipTo);
  98:        so.setItem(items);
  99:        return so;
 100:     }
 101:  }




 


As you can see, is quite easy, serialize as de-serialize the XML with Xstream.


The framework is quite small though powerful and easy to use, make it as one excellent option.

Monday, 13 September 2010

A Few Things To Take In Consideration Before Start One Agile Project

For my experience, that is more than twenty years in IT, and since beginning did try do some sort of Agile (beginning in 1991), when the project wasn’t big and one mix with Waterfall when with Enterprise solutions. Today by experience I’d know that is quite possible develop Enterprise solutions using Agile though a lot of things has changes since when. Especially with IDEs that 15-20 years ago where nearly inexistent, my preferred editor was the NE the good and old Norton Editor in DOS and  into Unix and Xenix  (if you do remember this last one, you should be considered a Dinosaur from IT, just like me!).

Must have more items to thing about it, though those ones for me are like the basics ones and will explain each one here. I know that some people may will say, “Aaaahhhh the number one isn’t true, the number X isn’t too, or even that this guy doesn’t understand about Agile”, however the truth is that I’d never have delivered one project with delays and the conclusion you should be take for yourself.

One thing for sure I’m not. I’m note that guy who want use EJB X, or Spring and bloat the system with patterns when isn’t needed. I like to talk technical language, though when talking with Juniors, is better you do use some examples with some sort of analogy that they will understand quite better. Be technical is good for who can understand, for those ones that are just starting, is one little bit scaring you be too technical. I think that they should have time to get there, and the first thing in one project that they need to know is, ‘know’ what they have to implement, and that they have one team leader that will be a team leader in fact. Teaching and explaining things when they need, they must feel that you are like a friend, that they can ask you anything about the project, language, patterns or correlated things without fear to be ridiculous. Doing this for sure they will have one better production and will close the gap about the system and those technologies involved.

You for sure should manage the code creation and have some patterns or conventions about it, and let your team familiarized with it as soon as the project starts. Comments exist and make then use it, explanations are never enough. This will help a lot when someone have to enhance or update the system.

If enhancing/updating or even maintaining one old system, to just create new classes and methods when strictly necessary, even that the code is the real bad quality. If you have time to re-write it, cool do it, if not, keep with the strict that is delivery the system working well. Doesn’t creating unnecessary classes and methods believe or not make the production go fast and doesn’t change the system structure, even being a bas one. Because, may be the next one to ‘touch’ in the system, will be the creator or someone that has to read follow all steps that you did to understand it and if you starting changing it, for sure the system will become a Frankstein and for sure will be harder to maintain.

One thing that I always put as top priorities are those two ROI and Quality, that means delivery good code and working of course, and that match with what the client expect and that has paid for.

Now for you that doesn’t have enough experience making run one Agile project I do enumerated a few things that should help you. 

1 . Just juniors will never able to work with/implement it.

   Nothing against them though if you are the only Senior in the project, be ready to do a lot of extra hours and have to re-write a lot of code, not all juniors are equals, but most of then take long time to delivery something. So  if you want make it go right since beginning mix at least one rate of 1 to 1, that means one with experience and one junior. If you can’t do that, don’t put the project and yourself in risk, go for some sort of mix, or something that is there before, keep one backup that can help you when you do need at most. Most of juniors must be guided, due this they love RUP and any Waterfall, because take off their hands the responsibility.

 


2 . Only years and having worked in several projects will give you the expertise to make run one successful Agile project, the same way one senior struts developer will never be a good system architect.

    This means that rush to be something that you are not ready to be, will just make you frustrated, saying that Agile does not work, like I’d saw a lot in several places on internet. If you don’t have any expertise with it, try create pilot projects, easy things to implement and try keep some sort of back up in whatever methodology was there before. With time you will be able to start spotting the issues and the potentials source of problems and delivery have solutions for it. Usually even reading a lot you will struggle in your first projects. If at anytime you don’t feel secure, raise the flag and call for help, it’s better you be honest with yourself and with is paying you than wast time, money and probably  lost your job. This also means that if someone ask you something that you don’t know, keep the head up and say that you will research about it and soon will let he/she know about it.

 


3 . The team must have the 'I can do it' attitude and be a experienced and organized team (this is one of the most hard to put together).

     This is a must in Agile projects, if any person of your team is showing you be one little bit lazy with lack of this attitude, talk with him a few times, though don’t expend too much time if you feel that he/she doesn’t want to change, take he/she off from the project fast. You can see this for the meetings, usually in the beginning of the project I do those very short meeting every day, after some time when they are familiarized with each other, I do go for one maximum of 3 meeting weekly, though most of projects one or two weekly are more than enough.

 

4 . Just follow what the book does not help if you don't have a good experience.

     I think that doesn’t need explain too much this right. If you don’t have enough experience and just try follow one book, you are putting a lot of things in risk, and one these include you, that depending of where you are trying implement it, you can kill your career before even started.

 


5 . Does not exist one standard way to make run Agile projects though just conventions, good practices, nor formula.

   As do wrote here before, your experience and being successful in find the potential problems that will make you run with success one Agile project.
   

 

6 . Use TDD with average team, will not help, you'll need a good team.

    Try follow it, if not TDD, test a lot your system in all possible ways, fail gracefully if inevitable, pay a lot attention with those nulls pointer exceptions, test those business rules up to exhaustion,don’t be lazy and try ask for some team mate test your code, when you do test other code. Check the data’s, create Unit tests, for everything that you had created and if possible one that will perform all tasks one full process. Try keep more realistic possible those data’s that will help you spot any issue easier than with auto generated data’s. After has tested for data’s do loading test and performance tests. Those ones will give you one good idea of how many connections your system can handle, the maximum before fail, and memory used.


 

7 . Need have access to the people that have the knowledge about what is being developed, no access means lack of information and fail.

    Without access to those ones that have the knowledge about what is being developed is waste time with Agile, don’t do it, because you will create one system that just get close, or not of what your client need and with quite less documentation, that means if he/she want make those changes to make the system match with what they expect, will be quite hard, and even you not being there anymore they will blame you for sure. My opinion is… “Always leave leaving the door open for you”. No ones can have the next day as granted right!

 


8 . At last one person of your team must have expertise in all project phases, like from make the interviews up to deploy in production environment, and know most of configurations for the environment to be used, just code does not help.

    This is very important, if you don’t have this expertise don’t do it or find someone that can really help you when you need. Remember Murphy’s Law… “If something might go wrong… it will go wrong”, and probably this will happen when you less expected.

 


Because this, isn’t so easy implement agile in medium to big projects and it's expensive for the company have several good guys working with it, and means that after project done, they will need keep a few just to enhance the system after, or to do the maintenance.
Before start one project you should know at least these points before to decide for what methodology you should go.
Of course there are successful histories in all methodologies, though doesn't mean that it will work all the time, and one very important tip for you. If you fail, please keep the head in place, keep calm, and do the analysis of what went wrong and why, to do not repeat it next time.

These are a few tips that I’d use very often and hope that it help you when you’d need it.