~ubuntu-branches/ubuntu/trusty/jwchat/trusty

« back to all changes in this revision

Viewing changes to scripts/wcs_benchmark.java

  • Committer: Bazaar Package Importer
  • Author(s): Lincoln de Sousa, Lincoln de Sousa, Marcelo Jorge Vieira
  • Date: 2010-09-16 11:42:28 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100916114228-5s5ne28n1w6wrfbl
Tags: 1.0+dfsg-1
[Lincoln de Sousa]

* Switch to dpkg-source 3.0 (quilt) format
* Migrating package from cdbs to debhelper 7.0.50~
* Changing the rule get-orig-source to generate a dfsg compatible
  package striping swf files from the orig (Closes: #591962)
* Updated Standards-Version to 3.9.1
* Removing po-debconf from the Build-Depends-Indep list.

[Marcelo Jorge Vieira]

* Fixing the default backend
* Fixing Debugger dependency
* Changing information about packaging from old maintainers to
  Debian XMPP Team.
* Removing sound support.
* Setting a port for apache VirtualHost.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import java.io.*;
 
2
import java.net.*;
 
3
 
 
4
import java.util.Date;
 
5
import java.util.regex.*;
 
6
 
 
7
public class wcs_benchmark {
 
8
    static String hostname;
 
9
    static int wcs_port = 5280;
 
10
    static int users;
 
11
    static int offset = 0;
 
12
    
 
13
    static HttpURLConnection httpcon;
 
14
    static String sids[]; // he we store the sids from logged in users
 
15
 
 
16
    /* default values as they are used in jabber testsuite */
 
17
    static String user_prefix = "test_";
 
18
    static String pass = "password";
 
19
 
 
20
 
 
21
    static int num_threads = 16;
 
22
    static Thread threads[];
 
23
 
 
24
    static String default_message = "HalloWelt";
 
25
 
 
26
    public static void usage() {
 
27
        System.out.println("java wcs_benchmark <host>:[port] <users> [offset]");
 
28
        System.exit(0);
 
29
    }
 
30
 
 
31
    public static String getURL(String url) {
 
32
        try {
 
33
            httpcon = (HttpURLConnection)(new URL("http",hostname,wcs_port,url)).openConnection();
 
34
            //                System.out.println(httpcon.getResponseMessage());
 
35
            BufferedReader br = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
 
36
            
 
37
            String content;
 
38
            String retval = "";
 
39
            while ((content = br.readLine()) != null) { retval += content; }
 
40
            
 
41
            br.close();
 
42
            return retval;
 
43
        } catch (IOException e) {
 
44
            System.err.println(e.toString());
 
45
            return null;
 
46
        }
 
47
    }
 
48
 
 
49
    public static void main(String args[]) {
 
50
        /* do some command line parsing */
 
51
 
 
52
        if (args.length < 2 || args.length > 3)
 
53
            usage();
 
54
 
 
55
        if (args[0].indexOf(':') != -1) {
 
56
            hostname = args[0].substring(0,args[0].indexOf(':'));
 
57
            wcs_port = (new Integer(args[0].substring(args[0].indexOf(':')+1))).intValue();
 
58
        } else 
 
59
            hostname = args[0];
 
60
 
 
61
        users = (new Integer(args[1])).intValue();
 
62
        sids = new String[users];
 
63
        
 
64
        if (args.length == 3)
 
65
            offset = new Integer(args[2]).intValue();
 
66
 
 
67
        threads = new Thread[num_threads];
 
68
 
 
69
        /*
 
70
         * log in users 
 
71
         */
 
72
 
 
73
        System.out.print("Logging in "+ users+" users ");
 
74
        Date starttime = new Date();
 
75
 
 
76
        Pattern sid = Pattern.compile(".*jabber.sid='(.*)';.*");
 
77
 
 
78
        for (int i=offset; i<users+offset; i++) {
 
79
            String url = "/login-sid.js?jid="+user_prefix+i+"@"+hostname+"&pass="+pass;
 
80
 
 
81
            Matcher m = sid.matcher(getURL(url));
 
82
            if (m.matches())
 
83
                sids[i-offset] = m.group(1);
 
84
            else {
 
85
                System.err.println("Couldn't get sid for user test_"+i);
 
86
                System.exit(1);
 
87
            }
 
88
 
 
89
            /* send presence */
 
90
            getURL("/presence.js?sid="+sids[i-offset]+"&status=available");
 
91
 
 
92
            /* get roster */
 
93
            getURL("/roster.js?sid="+sids[i-offset]);
 
94
 
 
95
            System.out.print(".");
 
96
        }
 
97
 
 
98
        Date endtime = new Date();
 
99
 
 
100
        System.out.println(" done (" + (endtime.getTime()-starttime.getTime())/1000.0 + "sec.)");
 
101
 
 
102
//         for (int i=0;i<sids.length;i++)
 
103
//             System.out.println(sids[i]);
 
104
 
 
105
        /*
 
106
         * created workers and let them work
 
107
         */
 
108
//         for (int i=0; i<threads.length; i++)
 
109
//             threads[i] = new Thread(new BenchmarkWorker(i));
 
110
//         for (int i=0; i<threads.length; i++)
 
111
//             threads[i].start();
 
112
//         for (int i=0; i<threads.length; i++)
 
113
//             threads[i].join();
 
114
 
 
115
 
 
116
        int request_counter = 0;
 
117
 
 
118
        java.util.Random rand = new java.util.Random();
 
119
        starttime = new Date();
 
120
        int num_requests = 10000;
 
121
        while (request_counter++ < num_requests) {
 
122
            String urls[];
 
123
            if (request_counter%10==0) {
 
124
                urls = new String[4];
 
125
                urls[0] = "/logout-sid.js?sid=";
 
126
                urls[1] = "/login-sid.js";
 
127
                urls[2] = "/presence.js?sid=";
 
128
                urls[3] = "/roster.js?sid=";
 
129
                System.out.print(" L");
 
130
            } else if (request_counter%3==0) {
 
131
                urls = new String[1];
 
132
                urls[0] = "/message.js?body="+default_message+"&sid=";
 
133
                System.out.print(" M");
 
134
            } else {
 
135
                urls = new String[1];
 
136
                urls[0] = "/cache.js?sid=";
 
137
            }
 
138
 
 
139
            // choose user
 
140
            int user = rand.nextInt(users);
 
141
            //            System.out.print(" "+user);
 
142
 
 
143
            for (int i=0; i<urls.length; i++) {
 
144
                String url;
 
145
                if (urls[i].indexOf("login-sid") != -1) {
 
146
                    url = urls[i] + "?jid="+user_prefix+user+"@"+hostname+"&pass="+pass;
 
147
                    Matcher m = sid.matcher(getURL(url));
 
148
                    if (m.matches())
 
149
                        sids[i] = m.group(1);
 
150
                    else {
 
151
                        System.err.println("Couldn't get sid for user test_"+i);
 
152
                        System.exit(1);
 
153
                    }
 
154
                } else {
 
155
                    url = urls[i] + sids[user];
 
156
                    getURL(url);
 
157
                }
 
158
            }
 
159
        }
 
160
        
 
161
        endtime = new Date();
 
162
        double duration = (endtime.getTime()-starttime.getTime())/1000.0;
 
163
 
 
164
        System.out.println(" 1000 requests served in " + duration  + "sec. ("+num_requests/duration+"/sec)");
 
165
 
 
166
        /*
 
167
         * log out users 
 
168
         */
 
169
 
 
170
        System.out.print("Logging out users ");
 
171
        for (int i=0; i<users; i++) {
 
172
            String url = "/logout-sid.js?sid="+sids[i];
 
173
            getURL(url);
 
174
            System.out.print('.');
 
175
        }
 
176
        System.out.println(" done.");
 
177
    }
 
178
}