Wednesday, July 29, 2015

Binding a processes into CPUs in Ubuntu

In this post I'm going to show you how to bind a process into a particular CPU in Ubuntu. Usually the OS manages the processes and schedules the threads. There is no guarantee on which CPU your process is running, OS will schedule it based on the resource availability.

But there is a way to specify the CPU and bind your process into a CPU.

taskset -cp <CPU ID | CPU IDs> <Process ID>

Following is an sample to demonstrate how you can do that.

1. Sample code which consumes 100% CPU (for demo purposes)

class Test {
    public static void main(String args[]) {
        int i = 0;
        while (true) {
            i++;
        }
    }
}

2. Compile and run the above simple program

javac Test.java
java Test

3. Use the 'htop' to view the CPU usage

In the above screen shot you can see that my sample process is running in the CPU 2. But its not guaranteed that it will always remain in CPU2. The OS might assign it to another CPU at some point.

4.  Run the following command, it will assign the process 5982 permanently into 5th CPU (CPU # start at zero, hence the index 4 refers to 5th CPU.)

taskset -cp 4 5982


In the above screen shot you can see, that 100% CPU usage is now indicated in the CPU 5.

Monday, July 13, 2015

WSO2 BAM : How to change the scheduled time of a scripts in a toolbox

WSO2 Business Activity Monitor (WSO2BAM) [1] is a fully open source, complete solution for monitor/store a large amount of business related activities and understand business activities within SOA and Cloud deployments.

WSO2 BAM comes with predefined set of toolboxes.

A toolbox consist of several components
1. Stream definitions
2. Analytics scripts
3. Visualizations components

Non of the above 3 components are mandatory.
You can have a toolbox which has only Stream definitions and Analytics scripts but not Visualization components.

In WSO2 BAM, toolbox always get the precedence. Which means if you manually change anything related to any component published via a toolbox. It will be override once the server is restarted.

If you update,
1. Schedule time
This will update the schedule time, and newly update value will be only effective until the next restart. This will not get persisted. Once the server is started, schedule time will have the original value form the toolbox

2. Stream definition
If you change anything related to stream definition, it might cause some consistency issues. When the server is restarted, it will find that there is already a stream definition exist with the given name and the configurations are different. So an error will be logged.

So it is highly discouraged to manually modify the components deployed via a toolbox

The recommended way to change anything associated with a toolbox, is to,
1. Unzip the toolbox.
2. Make the necessary changes.
3. Create a zip the files again.
4. Rename the file as <toolbox_name>.tbox
5. Redeploy the toolbox

So, if you need to change the scheduled time of Service_Statistics_Monitoring Toolbox,
Get a copy of Service_Statistics_Monitoring.tbox file resides in [BAM_HOME]/repository/deployment/server/bam-toolbox directory.

Unzip the file. Open the file Service_Statistics_Monitoring/analytics/analyzers.properties

Set the following configuration according to your requirement
analyzers.scripts.script1.cron=0 0/20 * * * ?

Create a zip file and change the name of the file to Service_Statistics_Monitoring.tbox

And redeploy the toolbox.

Now your changes is embed into the toolbox and each time the toolbox is deployed, it will have the modified value.

[1] http://wso2.com/products/business-activity-monitor/

Tuesday, July 7, 2015

Publishing WSO2 APIM Statistics to WSO2 BAM

WSO2 API Manager (WSO2APIM) [1] is a fully open source, complete solution for creating, publishing and managing all aspects of an API and its lifecycle.

WSO2 Business Activity Monitor (WSO2BAM) [2] is a fully open source, complete solution for monitor/store a large amount of business related activities and understand business activities within SOA and Cloud deployments.

Users can use these two products together, which collectively gives total control over management and monitoring of APIs.

In this post I'm going to explain how APIM stat publishing and monitoring happens in WSO2APIM and WSO2BAM.

Configuring WSO2 APIM to publish statistics

You can find more information on setting up statistics publishing in [3]. Once you do your configurations, it should look like the below.

<APIM_HOME>/repository/conf/api-manager.xml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<APIUsageTracking>
    <!-- Enable/Disable the API usage tracker. -->
    <Enabled>true</Enabled>   
    <PublisherClass>org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageDataBridgeDataPublisher</PublisherClass>
    <ThriftPort>7614</ThriftPort> 
    <BAMServerURL>tcp://<BAM host IP>:7614/</BAMServerURL>
    <BAMUsername>admin</BAMUsername>
    <BAMPassword>admin</BAMPassword>
    <!-- JNDI name of the data source to be used for getting BAM statistics. This data source should
        be defined in the master-datasources.xml file in conf/datasources directory. -->
    <DataSourceName>jdbc/WSO2AM_STATS_DB</DataSourceName>
</APIUsageTracking>

<APIM_HOME>/repository/conf/datasources/master-datasources.xml


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<datasource>
    <name>WSO2AM_STATS_DB</name>
    <description>The datasource used for getting statistics to API Manager</description>
    <jndiConfig>
        <name>jdbc/WSO2AM_STATS_DB</name>
    </jndiConfig>
    <definition type="RDBMS">
        <configuration>
            <url>jdbc:mysql://localhost:3306/stats_db?autoReconnect=true&amp;</url>
            <username>db_username</username>
            <password>db_password</password>
            <driverClassName>com.mysql.jdbc.Driver</driverClassName>
            <maxActive>50</maxActive>
            <maxWait>60000</maxWait>
            <testOnBorrow>true</testOnBorrow>
            <validationQuery>SELECT 1</validationQuery>
            <validationInterval>30000</validationInterval>
         </configuration>
    </definition>
 </datasource>


Configuring WSO2 BAM


You can find more information on setting up statistics publishing in [3].

Note that you only need to copy API_Manager_Analytics.tbox into super tenant space. (No need to do any configuration in tenant space)




Above digram illustrate how the stat data is published and eventually view though the APIM Statistic view.

1. Statistics information about APIs from all the tenants are published to the WSO2 BAM via a single data publisher.

2.  API_Manager_Analytics.tbox has stream definitions and hive scripts needed to summarize statistics. These hive scripts get periodically executed and summarized data is pushed into a RDBMS.

3. When you visit statistics page in WSO2 APIM, it will retrieve summerized statistics form the RDBMS and shows it to you.

Note: If you need to view statistics of a API which is deployed in a particular tenant. Login in to WSO2 APIM in particular tenant and view statistics page.
(You don't need to do any additional configuration to support tenant specific statistics.)


[1] http://wso2.com/api-management/
[2] http://wso2.com/products/business-activity-monitor/
[3] https://docs.wso2.com/display/AM180/Publishing+API+Runtime+Statistics