Skip to content

Commit a1a256b

Browse files
authored
Efficient Network Streamer for MOOSE (#352)
* This version shows images perfectly well. do not use timestamp since their value will not compare with timestamp of artifacts on different machines. * Temp commit. * CTRL+C is still not behaving well. * Socket information is separated and stored in one class. * os.file.isfile does not work with UNIX_DOMAIN_SOCKET. use os.path.exists. * Working version. Good for demo. * Updated a little. * Streaming is now flawless. * passes. * Local tests passes. * Good for demo. * Squashed commit of the following: commit 33fd75bf051e4799d2c37d3dc6cd59d3bbd73f42 Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Sat Feb 9 17:48:43 2019 +0530 Working fantastically with multiprocessing. commit 3fd5a8724e7b9cc0c681f44f4019ecb3844129eb Author: Dilawar Singh <dilawars@ncbs.res.in> Date: Sat Feb 9 16:29:59 2019 +0530 Split connect and stream function into two. * A decent working version. * updated a little bit more. * Small simulation do not steam all the data. Large simulations are working fine. * Working version. May be SocketStreamer is ticking too fast. * faster tests; non-blocking client. * use absolute import | python3 error in build. * folder name changed for reflect if PYTHON3 is being used. * Added some delay after start() * Fixes for OSX. * The last table is allowed to have slightly fewer elements. * Some more improvement.
1 parent 0f34490 commit a1a256b

27 files changed

+1092
-674
lines changed

.travis/travis_build_linux.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ if type $PYTHON3 > /dev/null; then
5858
sudo apt-get install -qq python3-networkx || echo "Error with apt"
5959
# GSL.
6060
(
61-
mkdir -p _GSL_BUILD2 && cd _GSL_BUILD2 && \
61+
mkdir -p _GSL_BUILD_PY3 && cd _GSL_BUILD_PY3 && \
6262
cmake -DPYTHON_EXECUTABLE="$PYTHON3" -DDEBUG=ON ..
6363
$MAKE && ctest --output-on-failure
6464
)
6565

6666
# BOOST
6767
(
68-
mkdir -p _BOOST_BUILD2 && cd _BOOST_BUILD2 && \
68+
mkdir -p _BOOST_BUILD_PY3 && cd _BOOST_BUILD_PY3 && \
6969
cmake -DWITH_BOOST_ODE=ON -DPYTHON_EXECUTABLE="$PYTHON3" ..
7070
$MAKE && ctest --output-on-failure
7171
)

basecode/ObjId.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ bool ObjId::isOffNode() const
112112

113113
char* ObjId::data() const
114114
{
115-
return id.element()->data( id.element()->rawIndex( dataIndex ),
116-
fieldIndex );
115+
return id.element()->data(
116+
id.element()->rawIndex( dataIndex ), fieldIndex
117+
);
117118
}
118119

119120
string ObjId::path() const

builtins/MooseSocketInfo.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Description: Utility class for handling socket.
3+
* Author: Dilawar Singh (), dilawars@ncbs.res.in
4+
* Organization: NCBS Bangalore
5+
*/
6+
7+
#ifndef MOOSESOCKETINFO_H
8+
#define MOOSESOCKETINFO_H
9+
10+
typedef enum t_socket_type_ {TCP_SOCKET, UNIX_DOMAIN_SOCKET} SocketType; // Type of socket.
11+
12+
class MooseSocketInfo
13+
{
14+
public:
15+
MooseSocketInfo( const string& addr = "" )
16+
: address(addr), valid(false)
17+
{
18+
if( addr.size() > 0 )
19+
init();
20+
}
21+
22+
~MooseSocketInfo() { ; }
23+
24+
void setAddress( const string addr )
25+
{
26+
address = addr;
27+
init();
28+
}
29+
30+
void init( void )
31+
{
32+
if( "file://" == address.substr(0, 7))
33+
{
34+
type = UNIX_DOMAIN_SOCKET;
35+
filepath = address.substr(7);
36+
valid = true;
37+
}
38+
else if( "http://" == address.substr(0, 7))
39+
{
40+
type = TCP_SOCKET;
41+
auto colPos = address.find_last_of(':');
42+
if( colPos == string::npos )
43+
{
44+
port = 0;
45+
host = address;
46+
}
47+
else
48+
{
49+
host = address.substr(0, colPos);
50+
port = std::stoi(address.substr(colPos+1));
51+
}
52+
valid = true;
53+
}
54+
else if( '/' == address[0] )
55+
{
56+
type = UNIX_DOMAIN_SOCKET;
57+
filepath = address;
58+
valid = true;
59+
}
60+
}
61+
62+
// C++ is so stupid: https://stackoverflow.com/q/476272/1805129
63+
friend std::ostream& operator<<(ostream& os, const MooseSocketInfo& info)
64+
{
65+
os << "ADDRESS= " << info.address << " TYPE= " << info.type;
66+
if( info.type == UNIX_DOMAIN_SOCKET)
67+
os << ". FILEPATH " << info.filepath;
68+
else
69+
os << ". HOST:PORT=" << info.host << ":" << info.port;
70+
return os;
71+
}
72+
73+
public:
74+
SocketType type;
75+
string address;
76+
string filepath;
77+
string host;
78+
bool valid;
79+
size_t port;
80+
};
81+
82+
83+
#endif /* end of include guard: MOOSESOCKETINFO_H */

0 commit comments

Comments
 (0)