Compilify is an online compiler that appears as a Service. Its founder is Justin rusbatch, which runs on Roslyn CTP [1. Since recently, it has been obtained from. netCommunity. We contacted Justin and asked him a few questions.
Infoq: Could you introduce yourself to our readers?
Justin:My name is Justin, a self-taught developer. I am now working in a small. Net-based Network Development Company in the middle of Pennsylvania. When I was a computer operator, I learned how to install tapes on the mainframe during night shifts #. I have been using ASP. NET for a year, but once the MVC framework was released, I moved it to it. Since then, I have developed several websites using the MVC framework. I also like to learn other languages and have a little understanding of Ruby on Rails, node. JS, and F.
Infoq: You recently started the compilify project.-What is the purpose?
Justin:Compilify is inspired by several things. One of the main sources of inspiration is the C # interactive window (C # interactive window) That Roslyn CTP brings to Visual Studio ). This window provides an alternative environment for executing individual statements on a development project and directly obtaining results.
Compilify makes the. NET compiler completely portable and can be accessed through quick interfaces, thus facilitating sharing and collaboration. It is not an integrated development environment (IDE) in a browser, and it will never be like that. In fact, it is much simpler than that. Just a few lines to testCodeYou do not need to start an integrated development environment (IDE) or create a console project. The developer's time is very precious. Just as ziyue says, "thinking without learning is just awkward", spending too much time thinking about problems without actually trying any solutions. This will only lead to over-designed solutions and killing productivity.
Compilify has great potential as a teaching tool to help beginners learn C. Downloading, installing, and starting Visual Studio may be daunting for new users. In fact, some developers may not be able to install Visual Studio because they have installed other applications that cannot be concurrently installed.Program-- This leads to a much more difficult experience. Compilify allows you to learn C # without installing any programs or even browser plug-ins #.
Infoq: How compilify works behind the scenes?
Justin:Its structure is very clever!
Once the user submits code to the server for execution, it will use signalr to establish a persistent connection. The Web server uses the signalr connection ID to package the received code into an object and add it to the processing queue on my redis server. This releases the Web server to continue processing requests from other users.
Although the processing process is simple, the processing tasks of the backend worker server are very heavy. To prevent any malicious code from running, a new low-trust application domain (appdomain) that acts as a Security Sandbox role is created each time the code is executed ). Although I haven't spent any time analyzing performance, so far, I don't have to worry about performance issues at this stage of the application. Because in the application domain (appdomain), in addition to user code, only some necessary assembly is loaded.
User code is first packaged into methods, parsed into compilation units, and then released to the program set. The Assembly is loaded inside the sandbox and the method encapsulated by the user code is called. The execution result is serialized and returned to the worker server. I execute these tasks in a separate thread so that I can cancel the processing in case it takes too long (currently the set time limit is 5 seconds.
Once the execution result is returned to the work server, the work server uses the corresponding signalr connection ID (this ID is obtained when the request was initially created to execute this code) and publish the execution results back to the redis server through the pub/SUB (publish/subscribe, publish/subscribe) channel. The Web server subscribes to this channel on app_start. Then, the signalr can forward any message to the corresponding client through this channel.
This complex architecture is necessary to facilitate secure execution of user code and ensure the stability of web servers.
Infoq: when you type the code, the editor will respond almost instantly. However, this still requires a round trip to the server. How do you do this?
Justin:The process of verifying user code starts in 0.5 seconds after the input is complete. The content in the editor will be sent to the server in post mode using standard Ajax requests. On the server, Roslyn is used to parse the code and check for various syntax or reference errors. However, once an error occurs, the process of releasing the compilation unit to the Assembly is actually terminated. Any errors are returned to the client and displayed to the user.
Infoq: How much time or effort have you spent building this project?
Justin:Before compilify was launched, I spent a week and a half working on this project. Of course, it is far from completion. In fact, the version I released in April 11 is only a conceptual verification. I hope to receive some feedback through the release of this version, and it is better to attract some interest-but what I did not expect is that the feedback received is almost the same as the traffic.
Infoq: In general, what is the traffic you receive, and how many front-end web servers and backend working servers do you need on average to meet the traffic requirements?
Justin:In the week since its launch in April 11, the number of website clicks has reached nearly 20,000. The user has saved, verified, or executed code more than 70,000 times. Most traffic occurs after Twitter found the site last week. After John Galloway posted a microblog comment on this site, a good load was generated-the number of concurrent sessions remained between 50 and 60. Scott hanselman then commented on the microblog. In less than five minutes, the value doubled, and the peak number of concurrent sessions was close to 170. Therefore, I must quickly adjust to three web servers and two background working servers to keep up with the increase in load.
As mentioned above, I did not expect this kind of traffic, and I may not be able to solve this problem if I don't have the help of my friends from appharbor. It is easy to contact them, and the information they give me helps identify the changes I can make to reduce load.
By keeping the redis queue between the web application (responsible for code verification) and the background working server (responsible for compiling and executing code), I can easily expand the application. If the queue starts to grow longer, I will add more backend working servers. If the frontend begins to become overwhelmed, I will add more web servers. New relic, an additional component for appharbor, allows me to easily monitor the loads of web servers and backend servers.
Infoq: What special learning experience can you share with rosyln, signalr, redis, or other components used in this project?
Justin:Although signalr is a powerful tool that is extremely easy to establish, pay attention to how you use it. Because it is also very fast, it makes people feel a little lightweight. I have made the mistake of opening the connection while loading the page but never closing it. This behavior is necessary for applications like http://jabbr.net (chat Applications created by David Fowler.
But in my case, you don't have to do that. I do not need to push messages to the client until the user clicks a link to run the code. Once the execution result is pushed to the client, the connection is not required. Since I enabled the connection on demand, the service load has dropped sharply. Although there are many examples of signalr, most of them are displaying some usage, such as jabbr, so they won't teach you how to close the connection.
Compilify is an open-source project on GitHub. The service is located on the appharbor cloud platform, and appharbor recently funded the project. They also published an interview with Justin on their blog, which contains more details.
Annotation
[1]Roslyn CTPTraditionally, compilers are black boxes --Source codeAccess from one end, and then the object file or assembly comes out from the other end. The Roslyn project changed this model by opening the VB and C # compilers. The compiler provides various APIs (application programming interfaces) so that tools and end users can share the rich information about the code that the compiler has. The new language object model can be previewed through Microsoft's "Roslyn" CTP (Community Technology preview, Community Technology Preview). This model is used for code generation, analysis, and refactoring, there will also be coming script support and interaction between C # and VB. For more information, see the Microsoft "Roslyn" CTP download page.
View Original English text:Compilify-compile. Net code in a browser
View the original Chinese Text : compilify -- let you compile. Net code in a browser