<commit_before>#!/usr/bin/env python

import os
import sys
import time
import random
import pdb

import nanomsg as nn

# deploy 2 sockets for intra process communication
s1 = nn.Socket(domain=nn.AF_SP, protocol=nn.REP)
s2 = nn.Socket(domain=nn.AF_SP, protocol=nn.REQ)
s3 = nn.Socket(domain=nn.AF_SP, protocol=nn.REQ)

# bind the two sockets to respective endpoints
s1.bind("inproc://test-1")

# connect the socket
s2.connect("inproc://test-1")
s3.connect("inproc://test-1")

client_list = ["s2", "s3"]
while(1):

  # choose the client to communicate
  client = random.choice(client_list)

  if client == 's2':

    # start communicating
    s2.send("hello from socket, s2")
    # field the request
    print s1.recv()
    # send a reponse back
    resp = 'hello from socket, s1'
    s1.send(resp)
    print s2.recv()

  elif client == 's3':

    # start communicating
    s3.send("hello from socket, s3")
    # field the request
    print s1.recv()
    # send a reponse back
    resp = 'hello from socket, s1'
    s1.send(resp)
    print s3.recv()

  time.sleep(1)  





<commit_msg>+ logic for stats collection<commit_after>#!/usr/bin/env python

import os
import sys
import time
import random
import pdb

import nanomsg as nn

# deploy 2 sockets for intra process communication
s1 = nn.Socket(domain=nn.AF_SP, protocol=nn.REP)
s2 = nn.Socket(domain=nn.AF_SP, protocol=nn.REQ)
s3 = nn.Socket(domain=nn.AF_SP, protocol=nn.REQ)

# bind the two sockets to respective endpoints
s1.bind("inproc://test-1")

# connect the socket
s2.connect("inproc://test-1")
s3.connect("inproc://test-1")

client_list = ["s2", "s3"]

# global counters messages processed by s1, s2 and s3
s1_msg_processed = 0
s2_msg_processed = 0
s3_msg_processed = 0

try:

  start_time = time.time()

  while(1):

    # choose the client to communicate
    client = random.choice(client_list)

    if client == 's2':

      # start communicating
      s2.send("hello from socket, s2")

      # field the request
      print s1.recv()

      # send a reponse back
      resp = 'hello from socket, s1'
      s1.send(resp)

      s1_msg_processed = s1_msg_processed + 1

      print s2.recv()

      s2_msg_processed = s2_msg_processed + 1

    elif client == 's3':

      # start communicating
      s3.send("hello from socket, s3")

      # field the request
      print s1.recv()

      # send a reponse back
      resp = 'hello from socket, s1'
      s1.send(resp)

      s1_msg_processed = s1_msg_processed + 1

      print s3.recv()

      s3_msg_processed = s3_msg_processed + 1

except KeyboardInterrupt, e:
  end_time = time.time()

  delta = end_time - start_time

  print 'total messages processed by s1: %s' % s1_msg_processed
  print 'total messages processed by s2: %s' % s2_msg_processed
  print 'total messages processed by s3: %s' % s3_msg_processed

  print 'messages processed by s1 per second: %s' % str(int(s1_msg_processed / delta))
  print 'messages processed by s2 per second: %s' % str(int(s2_msg_processed / delta))
  print 'messages processed by s3 per second: %s' % str(int(s3_msg_processed / delta))

{'fraction_non_alphanumeric': 0.11161436428340343, 'fraction_numerical': 0.028469750889679714, 'mean_word_length': 3.2472527472527473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2213991', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1063, 'n_words': 313}