challenge 分散関数呼び出し

分散関数呼び出しを実装してください.

呼び出される関数は,定価を整数で,割引率(%)を整数で受け取り,
文字列で「販売価格 ○円(定価○円から○%引き)」を返すものとします.
また,数字は3桁のカンマ区切りにするものとします.

たとえば,pricestring(2000, 20) なら
"販売価格 1,600円 (定価2,000円から20%引き)"
を返します.

関数の呼び出し元と,呼び出される側は,物理的に異なる
サーバに配置できることを条件とします.
呼び出し方法は問いませんが,呼び出し方法に名前がある場合,
それをタグに加えてください.
(XML-RPC,SOAP,CORBA,RMI,など)

また,作成した関数を直列に1万回呼び出して,
実行にかかった時間を測定してください.
測定時は別サーバでなくても構いません.
(なるべく別サーバが望ましいです)

測定環境として,
・サーバとクライアントのCPU・メモリ
・同一サーバ内での実行か別サーバでの実行か
・別サーバの場合,通信経路.(100Mbps Ethernet等)
・言語のバージョン
・ミドルウェアを使用している場合,その名前とバージョン
も併記してください.

1つの言語で複数の分散関数呼び出しの実装方法がある場合,
複数の回答を歓迎します.

出題の意図は,様々な分散呼び出し方法の実装例と,
レスポンス速度の確認にあります.
このお題は沢渡 みかげさんの投稿です。 まったく手を加えないでいい完成度の投稿で本当に助かります。 ありがとうございました。

Posted feedbacks - C#

同一マシンのCoreDuo1.5GHz で1万回11秒
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// サーバ
using System;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
  [WebMethod]
  public string Calc(int n, int r) {
    int p = n * (100 - r) / 100;
    return string.Format("販売価格 {0}円 (定価{1}円から{2}%引き)",
    p.ToString("C").Substring(1), n.ToString("C").Substring(1), r);
  }
}

// クライアント
using System;
using System.Diagnostics;
using HowWrite.localhost;
class Program
{
  static void Main()
  {
    Service srv = new Service();
    Stopwatch st = new Stopwatch();
    st.Start();
    string s = "";
    for (int i = 0; i < 10000; ++i) s = srv.Calc(2000, 20);
    Console.WriteLine(s);
    st.Stop();
    Console.WriteLine(st.ElapsedMilliseconds / 1000);
  }
}

.NET Remoting版
CoreDuo 1.5GHz の同一マシンで1万回2.7秒
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// サーバ用
using System;
public class Server : MarshalByRefObject
{
  public string Calc(int n, int r)
  {
    int p = n * (100 - r) / 100;
    return string.Format("販売価格 {0}円 (定価{1}円から{2}%引き)",
    p.ToString("C").Substring(1), n.ToString("C").Substring(1), r);
  }
}
class Program
{
  static void Main()
  {
    System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(
      new System.Runtime.Remoting.Channels.Tcp.TcpChannel(50000), false);
    System.Runtime.Remoting.RemotingConfiguration
      .RegisterWellKnownServiceType(typeof(Server), "HowWrite",
      System.Runtime.Remoting.WellKnownObjectMode.Singleton);
    System.Console.ReadKey();
  }
}

// クライアント用
using System;
using System.Diagnostics;
class Program
{
  static void Main()
  {
    Server  svr = (Server)Activator.GetObject(typeof(Server), 
      "tcp://localhost:50000/HowWrite");
    Stopwatch st = new Stopwatch();
    st.Start();
    string s = "";
	for (int i = 0; i < 10000; ++i) s = svr.Calc(2000, 20);
    Console.WriteLine(s);
    st.Stop();
    Console.WriteLine(st.ElapsedMilliseconds / 1000.0);
  }
}

Index

Feed

Other

Link

Pathtraq

loading...