ホームページ  >  記事  >  バックエンド開発  >  Web サイトのアーキテクチャと Spring MVC コード実践の進化

Web サイトのアーキテクチャと Spring MVC コード実践の進化

零到壹度
零到壹度オリジナル
2018-04-02 10:03:411642ブラウズ

この記事は、Spring MVC コードの実践の Web サイトのアーキテクチャと進化を共有します。内容は非常に優れており、困っている友人に役立つことを願っています

インフラストラクチャ。分解方法:

    標準OSI参照モデル
  • TCP/IP参照モデル
大量データのソリューション

Web サイトのアーキテクチャと Spring MVC コード実践の進化

  • キャッシングページの静的化

  • キャッシュ

    プログラムを通じてメモリに直接保存

    • キャッシュフレームワーク(Encache、Redis、Memcache)を使用

  • 静的ページ

    テンプレートテクノロジー(Velocity、FreeMakerなど)を使用して生成

  • データベース最適化

  • テーブル構造の最適化

  • SQLステートメントの最適化

  • パーティション

  • サブテーブル

  • インデックスの最適化

  • 直接操作プロシージャの代わりにストアドプロシージャを使用する

  • アクティブなデータを分離する

  • バッチ読み取りと遅延修正

  • 読書の分離そして

    Web サイトのアーキテクチャと Spring MVC コード実践の進化

  • 分散データベース

    Web サイトのアーキテクチャと Spring MVC コード実践の進化

  • NoSQLとHadoop

    を書いています


高同時実行ソリューション

  • 分離アプリケーションと静的リソースの統合: 静的ファイル (画像、ビデオ、JS、CSS など) は専用サーバーに配置されます

  • ページ キャッシュ (Nginx サーバー、Squid サーバー)

  • クラスター化および分散

  • リバースプロキシ

  • CDN

  • 基礎的な最適化: ネットワーク伝送プロトコル

共通のプロトコルと標準

TCP/IPプロトコル

IP: ルックアップアドレス、国際インターネットに対応

TCP: 標準化された伝送ルール、トランスポート層に対応

TCPは送信前に3回通信することを「3ウェイハンドシェイク」といい、データを送信した後、切断されると4回通信することを「4波」といいます。

TCP 2 つのシーケンス番号、3 つのフラグの意味:

  • seq: 送信されたデータのシーケンス番号を示します。 TCP送信時の各バイトにはシーケンス番号があり、受信が完了していない場合は、そのデータの最初のシーケンス番号が相手に送信されます。 、この方法でデータの整合性を保証できます。

  • ack: 確認番号を示します。受信側はこれを使用して、正常に受信されたデータ情報を送信側にフィードバックします。その値は、受信を希望する次のデータ パケットの開始シーケンス番号です。

  • ACK: 確認応答ビット、ACK は ACK = 1 の場合にのみ機能します。通常通信時のACKは1です。初回リクエスト時は確認する必要のあるデータがないためACKは0になります。

  • SYN: 接続を確立するときにシーケンス番号を同期するために使用される同期ビット。最初に接続が確立されたときは、受信したデータの履歴がないため、通常のメカニズムでは機能しません。受信側がこの問題を解決するのが SYN の役割です。 SYN = 1 レポート 書き込み時、ack は受信した seq + 1 の値に直接設定されます。ここでの値は検証後に設定されるのではなく、通常のメカニズムが実行できるように SYN に従って直接設定されることに注意してください。したがって、SYNは同期ビットと呼ばれます。通信の双方の ACK には初期値を設定する必要があるため、最初の 2 つのハンドシェイクでは SYN は 1 になります。

  • FIN: データ送信完了後に接続を解放するために使用される終了ビット。 DNS 設定 nDns 分析

  • 参照ドメイン名設定、次のとおり、Tencent クラウド ドメイン名の設定

Web サイトのアーキテクチャと Spring MVC コード実践の進化


レコード タイプ:

A レコード: ドメイン名が IPv4 アドレスを指すようにします (例: 8.8.8.8)

CNAME: ドメイン名が別のドメイン名を指すようにします (例: www.54tianzhisheng.cn)

MX : メールサーバーのアドレスを指すドメイン名

TXT: 任意に入力可能、長さ制限は 255、通常 SPF レコード (スパム対策)

NS: ドメインネームサーバーレコード、サブドメイン名を指定解決のために他の DNS サーバーに送信します

AAAA: ドメイン名を変更します iPv6 アドレスを指すようにします (例: ff06:0:0:0:0:0:0:c3)

SRV: サーバーを記録します特定のサービスを提供します (例: xmpp-server.tcp)

明示的 URL : ドメイン名 301 を別のアドレスにリダイレクトします

暗黙的 URL: 明示的 URL と似ていますが、実際のターゲット アドレスは非表示になります

ホストレコード:

www.54tianzhisheng.cn を解決するには、 www と入力してください。 ホスト レコードはドメイン名のプレフィックスです。一般的な使用法は次のとおりです:

www: *解決されたドメイン名は www.54tianzhisheng.cn です。

*@: メイン ドメイン名 54tianzhisheng.cn を直接解決します。

*: 汎分析、他のすべてのドメイン名 *.54tianzhisheng.cn と一致します。

mail: は、ドメイン名を mail.54tianzhisheng.cn に解決します。これは通常、メールボックス サーバーを解決するために使用されます。

第 2 レベル ドメイン名: 例: abc.54tianzhisheng.cn、abc を入力します。

モバイルウェブサイト: 例: m.54tianzhisheng.cn、mと入力します。


JavaにおけるSocketの使い方

通常のSocketの使い方

SocketはServerSocketとSocketの2つに分類されます。

ServerSocket はサーバー側で使用され、accept メソッドを通じてリクエストをリッスンし、

Socket ユーザーがデータ送信を完了した後にソケットを返します。クライアントは直接 Socket を使用してリクエストを送信し、送信します。データ。

一方的にメッセージを送信するデモを書きました:

クライアント:

  1. <span style="color:rgb(199,146,234);line-height:20px;font-size:13px !important;white-space: !important;">import</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;"> java</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;">io</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(126,165,247);line-height:20px;font-size:13px !important;white-space: !important;">IOException</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">;</span>

  2. <span style=" color:rgb(199,146,234);line-height:20px;font-size:13px ! important;white-space: ! important;">import<code style="margin-left:-20px;line-height:12px;border-width:0px;font-size:10px;font-family:inherit !important;"><span style="color:rgb(199,146,234);line-height:20px;font-size:13px !important;white-space: !important;">import</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;"> java</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;">io</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(126,165,247);line-height:20px;font-size:13px !important;white-space: !important;">OutputStream</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">;</span>

  3. <span style="color:rgb(199,146,234);line-height:20px;font-size:13px !important;white-space: !important;">import</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;"> java</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;">net</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(126,165,247);line-height:20px;font-size:13px !important;white-space: !important;">Socket</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">;</span>

  4. <span style="color:rgb(79,103,117);line-height:20px;font-size:13px !important;white-space: !important;">/**</span>

  5. <span style="color:rgb(79,103,117);line-height:20px;font-size:13px !important;white-space: !important;"> * Created by 10412 on 2017/5/2.</span>

  6. <span style="color:rgb(79,103,117);line-height:20px;font-size:13px !important;white-space: !important;"> * TCP客户端:</span>

  7. <span style="color:rgb(79,103,117);line-height:20px;font-size:13px !important;white-space: !important;"> ①:建立tcp的socket服务,最好明确具体的地址和端口。这个对象在创建时,就已经可以对指定ip和端口进行连接(三次握手)。</span> java.io

    .🎜OutputStream🎜;🎜🎜🎜🎜🎜🎜🎜🎜🎜<span style="color:rgb(199,146,234);line-height:20px;font-size:13px ! important;white-space: ! important;">import🎜<span style="color: rgb(238,255,255);line-height:20px;font-size:13px !重要;ホワイトスペース: !重要;"> java🎜<span style="color:rgb(204,204,204);line-height:20px;font-サイズ:13px !重要;空白: !重要;">.🎜<span style="color:rgb(238,255,255);line-height:20px;font-size:13px !重要;空白: !重要; ">net🎜<span style="color:rgb(204,204,204);line-height:20px;font-size:13px ! important;white-space: ! important;">.🎜<span style="color:rgb( 126,165,247);line-height:20px;font-size:13px ! important;white-space: ! important;">ソケット🎜<span style="color:rgb(204,204,204);line-height:20px;font-size: 13px !重要;空白: !重要;">;🎜</span></span></span></span></span></span></span>🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜🎜<span style="color:rgb(79,103,117);line-height:20px;font-size:13px ! important;white-space: !重要;">/**🎜</span>🎜🎜🎜🎜🎜🎜🎜🎜<span style="color:rgb(79,103,117);line-height:20px;font-size:13px ! important;white-space: ! important;"> * 10412 によって作成されました。 2017/5/2.🎜</span>🎜🎜🎜🎜🎜🎜🎜🎜<span style="color:rgb(79,103,117);line-height:20px;font-size:13px ! important;white-space: ! important;"> * TCP 客户端:🎜 </span>🎜🎜🎜🎜🎜🎜🎜🎜<span style="color:rgb(79,103,117);line-height:20px;font-size:13px ! important;white-space: ! important;"> ①:建立tcpのソケット服务、最好明确特定的このオブジェクトは、構築時に指定された IP とポートを接続することができます (三重ハンド)。</span>
  8. <span style=" color:rgb(79,103,117);line-height:20px;font-size:13px ! important;white-space: ! important;"> ②: 接続が成功した場合、チャネルが確立され、ソケット ストリームが確立されたことを意味します。生成されました。ソケット ストリームで読み取りストリームと書き込みストリームを取得し、getInputStream と getOutputStream を通じて 2 つのストリーム オブジェクトを取得するだけです。 <code style="margin-left:-20px;line-height:12px;border-width:0px;font-size:10px;font-family:inherit !important;"><span style="color:rgb(79,103,117);line-height:20px;font-size:13px !important;white-space: !important;"> ②:如果连接成功,就意味着通道建立了,socket流就已经产生了。只要获取到socket流中的读取流和写入流即可,只要通过getInputStream和getOutputStream就可以获取两个流对象。</span>

  9. <span style="color:rgb(79,103,117);line-height:20px;font-size:13px !important;white-space: !important;"> ③:关闭资源。</span>

  10. */
    //单方面的输入!
    public class TcpClient
    {
        public static void main(String[] args) {
            try {
                Socket s = new Socket("127.0.0.1", 9999);
                OutputStream o = s.getOutputStream();
                o.write("tcp sssss".getBytes());
                s.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

服务器端:

  1. <span style="color:rgb(199,146,234);line-height:20px;font-size:13px !important;white-space: !important;">import</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;"> java</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;">io</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(126,165,247);line-height:20px;font-size:13px !important;white-space: !important;">IOException</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">;</span>

  2. <span style="color:rgb(199,146,234);line-height:20px;font-size:13px !important;white-space: !important;">import</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;"> java</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;">io</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(126,165,247);line-height:20px;font-size:13px !important;white-space: !important;">InputStream</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">;</span>

  3. <span style="color:rgb(199,146,234);line-height:20px;font-size:13px !important;white-space: !important;">import</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;"> java</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;">net</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(126,165,247);line-height:20px;font-size:13px !important;white-space: !important;">ServerSocket</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">;</span>

    🎜🎜🎜🎜🎜<span style="color:rgb(79,103,117);line-height:20px;font-size:13px ! important;white-space: ! important;"> ③: リソースを閉じます。 🎜</span>🎜🎜🎜🎜🎜
    /**
     * Created by 10412 on 2017/5/2.
     */
    public class TcpServer
    {
        public static void main(String[] args) {
            try {
                ServerSocket ss = new ServerSocket(9999);//建立服务端的socket服务
                Socket s = ss.accept();//获取客户端对象
                String ip = s.getInetAddress().getHostAddress();
                int port = s.getPort();
                System.out.println(ip + " : " + port + " connected");
                // 可以通过获取到的socket对象中的socket流和具体的客户端进行通讯。
                InputStream ins = s.getInputStream();//读取客户端的数据,使用客户端对象的socket读取流
                byte[] bytes = new byte[1024];
                int len = ins.read(bytes);
                String text = new String(bytes, 0, len);
                System.out.println(text);
                //关闭资源
                s.close();
                ss.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    🎜

サーバー終了: 🎜

    🎜🎜🎜🎜<span style="color:rgb(199,146,234);line-height:20px;font-size:13px ! important;white-space : ! important;">import🎜<span style="color:rgb(238,255,255);line-height:20px;font-size:13px ! important;white-space: ! important;"> java🎜<span style=" color :rgb(204,204,204);line-height:20px;font-size:13px !重要;空白: !重要;">.🎜<span style="color:rgb(238,255,255);line-height:20px; -size:13px !重要;空白: !重要;">io🎜<span style="color:rgb(204,204,204);line-height:20px;font-size:13px !重要;空白: !重要;">.🎜<span style="color:rgb(126,165,247);line-height:20px;font-size:13px ! important;white-space: ! important;">IOException🎜<span style="color: rgb (204,204,204);line-height:20px;font-size:13px !重要;空白: !重要;">;🎜</span></span></span></span></span></span></span>🎜🎜🎜🎜🎜🎜🎜🎜<span style="color:rgb(199,146,234);line-height:20px; -size:13px !重要;空白: !重要;">インポート🎜<span style="color:rgb(238,255,255);line-height:20px;font-size:13px !重要;空白: !重要;">java🎜<span style="color:rgb(204,204,204);line-height:20px;font-size:13px ! important;white-space: ! important;">.🎜<span style="color: rgb (238,255,255);line-height:20px;font-size:13px ! important;white-space: ! important;">io🎜<span style="color:rgb(204,204,204);line-height:20px;font-size :13px !重要;空白: !重要;">.🎜<span style="color:rgb(126,165,247);line-height:20px;font-size:13px !重要;空白: !重要; >InputStream🎜<span style=" color:rgb important>;🎜</span></span></span></span></span></span>🎜🎜🎜🎜🎜 🎜 🎜🎜<span style="color: rgb (199,146,234);line-height:20px;font-size:13px ! important;white-space: ! important;">import🎜<span style="color:rgb(238,255,255);line-height:20px;font- size :13px !重要;空白: !重要;">java🎜<span style="color:rgb(204,204,204);line-height:20px;font-size:13px !重要;空白: !重要; >.🎜<span style=" color:rgb important>net🎜<span style="color:rgb( 204,204,204 );line-height:20px;font-size:13px !重要;空白: !重要;">.🎜<span style="color:rgb(126,165,247);line-height:20px;font-size: 13px !重要;空白: !重要;">ServerSocket🎜<span style="color:rgb(204,204,204);line-height:20px;font-size:13px !重要;空白: !重要;"> ; 🎜</span></span></span></span></span></span>🎜🎜🎜
  1. <span style="color:rgb(199,146,234);line-height:20px;font-size:13px !important;white-space: !important;">import</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;"> java</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(238,255,255);line-height:20px;font-size:13px !important;white-space: !important;">net</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">.</span><span style="color:rgb(126,165,247);line-height:20px;font-size:13px !important;white-space: !important;">Socket</span><span style="color:rgb(204,204,204);line-height:20px;font-size:13px !important;white-space: !important;">;</span>

  2. /**
     * Created by 10412 on 2017/5/2.
     */
    public class TcpServer
    {
        public static void main(String[] args) {
            try {
                ServerSocket ss = new ServerSocket(9999);//建立服务端的socket服务
                Socket s = ss.accept();//获取客户端对象
                String ip = s.getInetAddress().getHostAddress();
                int port = s.getPort();
                System.out.println(ip + " : " + port + " connected");
                // 可以通过获取到的socket对象中的socket流和具体的客户端进行通讯。
                InputStream ins = s.getInputStream();//读取客户端的数据,使用客户端对象的socket读取流
                byte[] bytes = new byte[1024];
                int len = ins.read(bytes);
                String text = new String(bytes, 0, len);
                System.out.println(text);
                //关闭资源
                s.close();
                ss.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

以上がWeb サイトのアーキテクチャと Spring MVC コード実践の進化の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:PHP仕様のPSR仕様次の記事:PHP仕様のPSR仕様